The problem is make a program that will display a corresponding letter grade to the ff. input values: A for 90 above, B for 80-89, C for 70-79, D for 60-69, and F for below 60 using switch/case statements.
The limits for A are 90%26lt;=A%26lt;=100; for 50%26lt;=F%26lt;=59. The default statement is "out of range". How do you input the syntax for the cases, complete with the %26lt;= and %26gt;= conditions? Just one example of a case (to follow and continue) will be great, thanks.
Switch/case statement in C help please?
in cases, we can't use %26lt;= or %26gt;=
one way to solve ur problem wud be:
void main()
{
int num,A,B,C,D,F;
printf("Enter a number: ");
scanf("%d",%26amp;num);
switch(A)
{
case 90:
case 91:
/*
..
.. u can fill the values in between..
*/
case 100: printf("grade is A"); break;
case 80:
case 81:
/*
..
.. fill the in between values
*/
case 89: printf("grade is B"); break;
/* similarly for other grades.. just remember to put break; statement on the last value of a given range for a grade */
default: printf("The number is out of range");
}
Reply:You need to use if/else statement. Switch won't allow that type of checking.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment