+ 1

Why isn't it working

#include <iostream> using namespace std; int main() { string a int b,c; cin>>a; cin>>b; cin>>c;} if(a=add){ cout<<a+b; } if(a=multiply){ cout<<a*b; } return 0; }

28th May 2018, 7:48 AM
Vikram
Vikram - avatar
3 odpowiedzi
+ 7
#include <iostream> using namespace std; int main() { string a int b,c; cin>>a; cin>>b; cin>>c; if(a=="add"){ cout<<b+c; } if(a=="multiply"){ cout<<b*c; } return 0; } Vikram
28th May 2018, 9:59 AM
Hatsy Rei
Hatsy Rei - avatar
+ 3
string a; //you forgot a semicolon cin >> c; //no '}' if (a=="add" ) { //= means assignment in C++. You are trying to give a the value add. == is the equality comparison. Moreover a == add checks to see wether the variable a has the same value as the variable add. "add", with quotation marks, refers to the value itself. if (a=="multiply") {
28th May 2018, 7:52 AM
Vlad Serbu
Vlad Serbu - avatar
+ 1
thank you sir
28th May 2018, 7:59 AM
Vikram
Vikram - avatar