0

Do While String Question

This is not working for some reason. Please help! //Do loop to make sure input is 1, 2 or 3 only do { //Opening input question. Console.WriteLine("Type a number: rock(1) paper(2) or scissors(3)"); //Sets string variable based on user input choice = Convert.ToString(Console.ReadLine()); } while (choice != "1" || choice != "2" || choice != "3"); Console.WriteLine("shipoopy");

1st Dec 2016, 3:50 PM
Dale Allen Burns Jr.
Dale Allen Burns Jr. - avatar
4 Respuestas
+ 6
choice is not initialized. Write it as: string choice = Console.ReadLine(); ReadLine() always returns a string, so no need to convert. Use && instead of || for the condition, otherwise you'll stay in the loop even with the right input.
1st Dec 2016, 4:06 PM
Tamra
Tamra - avatar
+ 4
You didn't even set something : int choice = 0; Place it before the while loop. In the while loop : choice = Console.ReadLine();
1st Dec 2016, 3:53 PM
Wen Qin
Wen Qin - avatar
+ 2
I had already declared the CHOICE variable. Using && instead of || made it work!
1st Dec 2016, 5:23 PM
Dale Allen Burns Jr.
Dale Allen Burns Jr. - avatar
+ 1
1st Dec 2016, 4:07 PM
Maxim Konstantinovski
Maxim Konstantinovski - avatar