+ 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: ");
5 odpowiedzi
+ 6
ramandeep kaur Try this approach:
https://code.sololearn.com/c5hSxLfAcfpW/?ref=app
+ 1
this is not opening error code404
+ 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
}
+ 1
if else is not allowed ...............
0
Is switch statement allowed? if it is, then you can try switching the valid options instead ...