vendredi 23 avril 2021

C# If....Else statement ignoring the condition

Console.WriteLine("What type of calculation do you want to perform? (+, -, *, /, %)");
        V = Console.ReadLine();

        if (V == "+" || V == "-" || V == "*" || V == "/" || V == "%")
        {
            Console.WriteLine("Enter the value of y");
            y = Convert.ToInt32(Console.ReadLine());
        }
        else
        {
            Console.WriteLine("Enter a valid operator type");
        }

for some reason, it ignores the condition, and whatever I type as a value of V it still asks me to enter the value of y. Ps: I'm a beginner obviously, I searched everywhere why this happens and I couldn't find any answers, I hope someone can help me out

Aucun commentaire:

Enregistrer un commentaire