Error on if(smth == smth)

Updated on August 12, 2018 in [A] C# .Net
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
1 on August 12, 2018

Heya, so I was watching brackeys c# tutos and I tried to spice my calculator up. But in the procedure i got an error.

            Start:
            double num01;
            double num02;
            char operation;
            Console.WriteLine("What operation would you like? (+, -, *, /)");
            operation = Convert.ToChar(Console.ReadKey());
            if (operation == +)<------------------------------ this last parenthesis give me error
            {
                Console.Write("Type a number to be added: ");
                num01 = Convert.ToDouble(Console.ReadLine());
                Console.Write("Type another number to add: ");
                num02 = Convert.ToDouble(Console.ReadLine());
                Console.WriteLine(num01 + " plus " + num02 + " equals " + num01 * num02);
                Console.ReadKey();
                Console.WriteLine();
                goto Start;
            }
  • Liked by
Reply
0 on August 12, 2018

Try this

if (operation == '+')

you need to make sure you’re comparing the right things. + on its own is TOTALLY different from the character for +.

  • Liked by
Reply
Cancel