+ 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?

4th Aug 2016, 2:00 AM
Playjoy “Kungpoww” Of Death
Playjoy “Kungpoww” Of Death - avatar
6 ответов
+ 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
30th Aug 2016, 12:34 PM
Ammar Ahmad
Ammar Ahmad - avatar
+ 2
you can use switch, or some if-s. Like if(playerScore<=74 && playerScore>=50){Console.WriteLine("good");}
4th Aug 2016, 4:34 AM
Róbert Pécz
Róbert Pécz - avatar
+ 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 .
4th Aug 2016, 6:40 AM
Javeria Khan
+ 2
If you want that, use an if else statment. Wurh switch statements you cannot use operators. It has to be an exact value.
16th Aug 2016, 3:28 PM
Taj K.
+ 1
use if statements
5th Aug 2016, 11:53 AM
Logan Kirkendoll
Logan Kirkendoll - avatar
+ 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.
1st Nov 2016, 5:50 PM
Uplabdhi Singh
Uplabdhi Singh - avatar