+ 1

how to show an error for the user input other than paper,rock and scissors in c#?

Console.WriteLine("\n please select your play from the followin statements..... \n"); Console.WriteLine("paper\n"); Console.WriteLine("rock"); Console.WriteLine("\nscissors\n"); selection = selection.ToLower(); Console.Write("Your selection: ");

6th Oct 2020, 6:18 AM
ramandeep kaur
5 odpowiedzi
6th Oct 2020, 7:42 AM
David Carroll
David Carroll - avatar
+ 1
this is not opening error code404
6th Oct 2020, 6:48 AM
ramandeep kaur
+ 1
Prepare a string array containing all the valid option, then use `Contains` method of the array to check whether the given input (<selection>) is one of the elements in the array. string[] choices = { "rock", "paper", "scissor" }; if(choices.Contains("paper")) { // ok } else { // not a valid option }
6th Oct 2020, 7:01 AM
Ipang
+ 1
if else is not allowed ...............
6th Oct 2020, 7:11 AM
ramandeep kaur
0
Is switch statement allowed? if it is, then you can try switching the valid options instead ...
6th Oct 2020, 7:14 AM
Ipang