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; }

3rd Sep 2017, 5:38 AM
Surendra Rajawat
Surendra Rajawat - avatar
12 odpowiedzi
+ 4
Too late ^^" but thanks c':
3rd Sep 2017, 6:13 AM
Dapper Mink
Dapper Mink - avatar
+ 3
Why did you set the operator as string , a character type will work .
3rd Sep 2017, 6:03 AM
RZK 022
RZK 022 - avatar
+ 3
Figured out operator is a keyword and that you should use char instead of string
3rd Sep 2017, 6:09 AM
Dapper Mink
Dapper Mink - avatar
+ 2
seems like it is, but you can check it by yourself using the SoloLearn compiler
3rd Sep 2017, 5:44 AM
Dapper Mink
Dapper Mink - avatar
+ 2
welp lemme check it
3rd Sep 2017, 5:50 AM
Dapper Mink
Dapper Mink - avatar
+ 2
Oooops, sorry o.O
3rd Sep 2017, 6:10 AM
Dapper Mink
Dapper Mink - avatar
+ 2
Didn't take the time to read lol, my apologies
3rd Sep 2017, 6:11 AM
Dapper Mink
Dapper Mink - avatar
+ 2
np, at least you got it figured out. 😉
3rd Sep 2017, 6:12 AM
ChaoticDawg
ChaoticDawg - avatar
+ 1
'operator' is a keyword you can't use it as a variable name!!! ... and yes char type will work just fine.
3rd Sep 2017, 6:07 AM
ChaoticDawg
ChaoticDawg - avatar
+ 1
yup, we literally just said that. lol
3rd Sep 2017, 6:10 AM
ChaoticDawg
ChaoticDawg - avatar
+ 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
3rd Sep 2017, 7:29 PM
HJ🐓TDM
0
doesn't work
3rd Sep 2017, 5:48 AM
Surendra Rajawat
Surendra Rajawat - avatar