Using switch case

Hello every one...can anyone make the following program using switch case rather than using if conditions...

Write a program to assign letter grade to given no according to following distribution
>=85=A,75-84=B,65-74=C,50-64=D, <50=F
We can't do your homework. Give it a first try and we'll be glad to help.

Here's a reference

http://www.cplusplus.com/doc/tutorial/control/
i am not assining the homework....its not essential to solve the problem using swtich....i can do it using if statement....but i cant find a way out using switch...thats why posted my problem here so i may be guided....please read this code and tell the mistake....the program runs but doesnt show any output



#include<iostream.h>
#include<conio.h>
#include<math.h>
main()
{
int marks;


cout<<"Enter the marks of the subject ";
cin>>marks;

switch(marks)
{
case 'marks>=85':
{
cout<<"The grade of the subject is A"
break;


}
}
getch();
}
Last edited on
switch statements are made to check equality. You can; however, always link your statement to a function that returns a value.

I, personally, don't use switch statements. I find it pointless to use it when I could use if/if else/else. The only time I used switch was when I created a table and needed to select an option for some operation... and it wasn't necessary, in fact.
If you want to handle all the marks >= 85 you have to list them all.
1
2
3
4
5
6
7
8
9
10
11
12
switch (marks)
{
case 85:
case 86:
case 87:
case 88:
case 89:
...
case WHATEVER_IS_THE_MAX_SCORE:
	cout<<"The grade of the subject is A"
	break;
...


Switch statements are more useful when you are checking for specific values. Much better to use if statements in this case.
thanks for the help guys...i will use if statement....as it would be weird to use case 85 case 86 and so on
Topic archived. No new replies allowed.