-
September 28th, 2013, 07:58 AM
#1
What is wrong with this simple code
using System;
class Program
{
static void Main
{
string userInput;
int userGrade;
Console.WriteLine("========================================================");
Console.WriteLine("Enter in your score to find out what grade you have got.");
Console.WriteLine("========================================================");
Console.WriteLine("");
userInput = Console.ReadLine;
userGrade = int.Parse(userInput);
switch (userGrade)
{
case <35:
Console.WriteLine("F");
break;
case >=35 && <=39:
Console.WriteLine("E");
break;
case >=40 && <=39:
Console.WriteLine("D");
break;
case >=50 && <=59:
Console.WriteLine("C");
break;
case >=60 && <=69:
Console.WriteLine("B");
break;
case >=70:
Console.WriteLine("A");
break;
}
}
}
-
September 28th, 2013, 08:49 AM
#2
Re: What is wrong with this simple code
I get an error saying, get and set accessors expected
-
September 28th, 2013, 10:52 AM
#3
Re: What is wrong with this simple code
I have progressed but all I need to do now it to get the switch statement to work with something like case <35:.
I can't only get it to work with case 1: ... etc..
Any possible way in doing this.
-
September 28th, 2013, 02:05 PM
#4
Re: What is wrong with this simple code
Use the default: case item and check for < 35 in there.
Keep in mind that you can 'stack' several case statements on top of each other, if that helps.
Code:
switch(value)
{
case 3:
case 6:
case 8:
DoWork();
break;
default:
if(value < 35)
{
DoOtherWork();
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|