mardi 2 juillet 2019

If statement problem: ignoring other statements even if its true(?)

Even if the user input matches the string operations, the statement always results to a false which in turn shows the error prompt.

pardon my code if it seems mediocre, I just started to learn programming for not less than a week. I believe my problem is too specific that's why I'm having a hard time finding a solution. Any will be appreciated.

Console.Write("What Operation?: ");

string input = Console.ReadLine();

if (input == "+")
{
   op = input;
}
if (input == "-")
{
   op = input;
}
if (input == "*")
{
   op = input;
}
if (input == "/")
{
   op = input;
}
else
{
   op = "Enter a valid operation!!!";
   Console.WriteLine(op);
   Console.ReadLine();
}

if the user writes the correct operation: it should store it to "op" then will be used for the equation.

Aucun commentaire:

Enregistrer un commentaire