0

C# Case problem (invalid expression term ,,:")

This is a code of a simple calculator that I'm trying to write, but there seem to be a problem with the switch statment (Visual Studio state that ,,invalid expression term ,,:"" and I really don't know why, because the code seems good to me.I want to add some more code later, but I don't want to continue before I don't deal with this problem. int x, y, sum; char input; do { Console.WriteLine("Enter a value for x:"); x = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Enter a value for y:"); y = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("What do you want to do? Add, substract, multiply or divide?"); input = Convert.ToChar(Console.ReadLine()); switch (input) { case + : sum = x + y; break; case - : sum = x - y; break; case * : sum = x * y; break; case '/': sum = x / y; break; } } while (true);

30th Aug 2020, 7:21 PM
Waser4K
Waser4K - avatar
3 Respostas
+ 2
for chars mention in single quotes.. '+' '-' '*' '/'
30th Aug 2020, 7:25 PM
Jayakrishna 🇮🇳
+ 1
Thanks, It works now :)
30th Aug 2020, 7:32 PM
Waser4K
Waser4K - avatar
+ 1
You're welcome...
30th Aug 2020, 7:33 PM
Jayakrishna 🇮🇳