C++ #if elif指令未按预期工作

C++ #if elif指令未按预期工作,c++,C++,我正在尝试使用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 ear

我正在尝试使用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;
}
#包括
使用名称空间std;
#定义a(t1)(t1+50)
#定义b(t2)(t2+100)
int main()
{
联合总经理
{
int t1;
int t2;
};
总经理c;

cout不能使用依赖于运行时变量值的预处理器宏

除非将
p
定义为预处理器宏

#if(p<500)

不能使用在运行时依赖于变量值的预处理器宏

除非将
p
定义为预处理器宏

#if(p<500)
if (p<500)
{
   cout <<"Points earned too less"<<endl;
}
else if (p>500 && p<1500)
{
   cout<<"You can play game 1 free"<<endl;
}
else if (p>1500 && p<2500)
{
   cout<<"You can play game 1 free"<<endl;
}
else if ( p>3000 )
{
   cout<<"You can play game 1 and game free"<<endl;
}
else
{
   // Do something for everything else.
}