0
Question to sololearn
Is this code right #include <iostream> using namespace std; int main () { int num1,num2; string operator; cout <<"Enter either addition or subtraction or multiplication or division or modulus="; cin>>operator; cout <<"Enter two numbers="; cin>>num1>>num2; switch (operator){ case "+": cout <<num1+num2; break; case "-": cout <<num1-num2; break; case "*": cout <<num1*num2; break; case "/": cout <<num1*num2; break; case "%": cout <<num1*num2; break; } return 0; }
12 odpowiedzi
+ 4
Too late ^^" but thanks c':
+ 3
Why did you set the operator as string , a character type will work .
+ 3
Figured out operator is a keyword and that you should use char instead of string
+ 2
seems like it is, but you can check it by yourself using the SoloLearn compiler
+ 2
welp lemme check it
+ 2
Oooops, sorry o.O
+ 2
Didn't take the time to read lol, my apologies
+ 2
np, at least you got it figured out. 😉
+ 1
'operator' is a keyword you can't use it as a variable name!!! ... and yes char type will work just fine.
+ 1
yup, we literally just said that. lol
+ 1
1. use char
2. if you don't want to, then at least add a string header
3. and change the name of it
0
doesn't work