-1

所以我输入了这段代码并出现了这个错误......请帮助......并提前感谢:)

double num1;
double num2;
double operation;
//input

   cout<<"Type The First number\n";
   cin>>num1;
   cout<<"Type Second number\n";
   cin>>num2;
   cout<<"Type The Operation..\n";
   cin>>operation;
   //Brain
   if (operation == + )
    {
      cout<<"The Answer is..."<<num1+num2;

并且错误是错误:')'令牌之前的预期主表达式|

4

2 回答 2

4

您正在将 adouble与 a进行比较+。这不是 PHP。:)

你的意思

std::string operation;

//...
if ( operation == "+" )
    //....
于 2012-09-24T15:32:17.480 回答
2

编译器不理解这个

if (operation == + )

您可能想声明operation为 a char,然后像这样测试它

if (operation == '+' )
于 2012-09-24T15:33:27.687 回答