+ 1

C# multiple choice

Im trying to create a multiple choice console application for school i just don’t know how to make the program accept both the answer “c” and “C” or making it ignore the capitalization.

22nd Feb 2021, 12:16 AM
Gold leaf
4 ответов
+ 1
Console.WriteLine(" Who are the Ti9 Champions?"); Console.WriteLine("A. OG*"); Console.WriteLine("B. EG"); Console.WriteLine("C. Liquid"); Console.WriteLine("D. Secret"); var answer1 = Console.ReadLine(); if (answer1 == "a") score++; if (answer1 == "a") Console.WriteLine("Correct!"); else Console.WriteLine("Wrong!"); This is my current code where should i place the string str?
22nd Feb 2021, 1:15 AM
Gold leaf
0
You can transform whole input to uppercase/lowercase, and then check it with switch, is that what are you asking for? Just like string str = "uppercase string"; str.ToUpper(); And you're done
22nd Feb 2021, 12:46 AM
Michal Doruch
0
"string answer1", you are reading string by default anyway. Then you can "answer1.ToUpper()", and your if statement does not have to be written twice, use brackets to put multiple lines of code in your "if" scope. Anyway, then "if" should check if the user input is 'A' instead of 'a' (cuz it's uppercase now). You can use "answer1.ToLower()" too, so input will become lowercase
22nd Feb 2021, 1:29 AM
Michal Doruch
0
thank you!
22nd Feb 2021, 1:39 AM
Gold leaf