1
我正在嘗試使用if elif來測試一個條件,但我沒有得到想要的結果。請幫助我確定我做錯了什麼?#if elif指令不能按要求工作
#include <iostream>
using namespace std;
#define a(t1)(t1+50)
#define b(t2)(t2+100)
int main()
{
union gm
{
int t1;
int t2;
};
gm c;
cout <<"Enter tokens earned in game 1: "<<endl;
cin>>c.t1;
int x=c.t1;
cout <<"Enter tokens earned in game 2: "<<endl;
cin>>c.t2;
int y=c.t2;
int m= a(x)+100;
int n= b(y)+50;
int p;
p=m+n;
cout <<p<<endl;
#if(p<500)
cout <<"Points earned too less"<<endl;
#elif (p>500 && p<1500)
cout<<"You can play game 1 free"<<endl;
#elif (p>1500 && p<2500)
cout<<"You can play game 1 free"<<endl;
#elif p>3000
cout<<"You can play game 1 and game free"<<endl;
#endif
return 0;
}
當P的值超過500時,仍顯示消息「積分得分太少」。
請幫忙。
謝謝,薩胡先生 –
@ArtiDeshpande,不客氣。我很樂意提供幫助。 –