简体   繁体   English

')' 标记前的预期主表达式错误

[英]error expected primary-expression before ')' token

14:15: error: expected primary-expression before ')' token and 18:20: error: expected primary-expression before ')' token 14:15:错误:')' 标记之前的预期主表达式和 18:20:错误:')' 标记之前的预期主表达式

here's my code这是我的代码

#include <iostream>
#include <string>
using namespace std;

int main () 
{
   // local variable declaration:
   int a;
   cout<<"masukkan operasi = "; cin >> a;
   int angka1;
   cout<<"masukkan angka = ";cin >> angka1;
   int angka2;
   cout<<"masukkan angka = ";cin >> angka2;
   if( a == + ) 
   {
      cout <<"Hasil = " << angka1+angka2 <<endl ; //hasil
   } 
   else if( a == * ) 
   {
       cout <<"Hasil = " << angka1*angka2 <<endl ;
   }
}

pls help me, i'm new to c++请帮助我,我是 C++ 新手

if( a == + )

In the above line a is an integer, but you are trying to read + or * which are charecters.在上面的行中, a是一个整数,但您正在尝试读取+* ,它们是字符。 So first change the line int a;所以首先改变行int a; to char a; char a; . . Next change the line if( a == + ) to if( a == '+') .接下来将if( a == + )行更改为if( a == '+') Similarly do it for else case.对其他情况同样这样做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM