Why doesn't this bit of C++ code work | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
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

24th Jul 2022, 3:17 PM
Cooper
Cooper - avatar
3 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; }
24th Jul 2022, 3:31 PM
Ani Jona 🕊
Ani Jona 🕊 - avatar
+ 2
https://code.sololearn.com/cgGlCsc4jvAD/?ref=app Everything is already explained by Ani Jona 🕊 so, nothing have to explain.
24th Jul 2022, 4:10 PM
Pallavi Jha
Pallavi Jha - avatar
+ 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 .
24th Jul 2022, 4:40 PM
A S Raghuvanshi
A S Raghuvanshi - avatar