+ 1
How to make a case respond to multiple values?
Let's say I want to give the player a grade based on there score (Perfect = 100, Great = 99-75, Good = 74-50, failed= 49-0) How could I make the case accept a 76 as great without creating 100 cases?
6 Answers
+ 6
Paste this code in your code window and try to compile its my code :)
you will understand how it works :)
in this code i'm using switch statement to analyse user input :)
you can use it in your way after understanding it..
if you have any problem regarding understanding you can reply to this post ;)
dont forget to thumbs up :)
static void Main(string[] args)
{
Console.Write("Enter Something for Checking : ");
char choiceNumber;
choiceNumber = Convert.ToChar(Console.ReadLine());
switch (choiceNumber)
{
case 'a':
Console.WriteLine("something 1");
break;
case 'b':
Console.WriteLine("something 2");
break;
case 'c':
Console.WriteLine("something 3");
break;
default:
Console.WriteLine("You Failed :( ");
break;
}
Console.ReadLine();
you can also use it with the int, bool or any other data types ;) try it
+ 2
you can use switch, or some if-s. Like if(playerScore<=74 && playerScore>=50){Console.WriteLine("good");}
+ 2
using switch will take more time as you will have to write all the values as case constants. if-else constructs are more easier to implement in such cases .
+ 2
If you want that, use an if else statment. Wurh switch statements you cannot use operators. It has to be an exact value.
+ 1
use if statements
+ 1
You can use if statements in the case. After deciding the cases.. You can insert if statements there inside those cases and if statements should contain particular conditions. Then also add the print statement for the output of that condition.