0
Why doesn't this bit of C++ code work
I'm trying to make a calculator and if just won't work https://code.sololearn.com/cCZaywAGTsjX/?ref=app
4 Antworten
+ 3
You need a to be of type char because you are reading a symbol.
Further, to compare, you need two equal signs (==), otherwise it is an assignment. And compare against a char symbol by putting the symbol in single quotes. Below you see an example. Try to extend it to the other operations as well.
char a;
cout << "answer \n";
cin >> a;
cin >> x;
cin >> y;
if ( a == '*' ){
z = x * y;
}
+ 2
https://code.sololearn.com/cgGlCsc4jvAD/?ref=app
Everything is already explained by Ani Jona 🕊 so, nothing have to explain.
+ 2
Integer and characters have difference your a variable should be char types and in if conditions write characters in single quotes . you have to write conditions .