Hey Guys,
So I have to write a program, using the switch statement, that allows a user to enter a percentage mark, and output the corresponding letter grade. This is what I've come up with so far. It compiles, but whenever a number is entered the program quits......
Am i not returning properly?
Any help would be greatly appreciated. Thanks in advance. Cheers.
Code:
#include <stdio.h>
int main()
{
int num_grade, tens;
printf("Enter numerical grade:");
scanf("%d", &num_grade);
if ((num_grade < 0) || (num_grade > 100)) {
printf("Grade must be positive AND less than 100.\n");
}
else {
tens = num_grade / 10;
switch (tens) {
case 0: printf("The grade is F.\n");
break;
case 1:printf("The grade is F.\n");
break;
case 2:printf("The grade is F.\n");
break;
case 3:printf("The grade is F.\n");
break;
case 4:printf("The grade is F.\n");
break;
case 5: printf("The grade is F.\n");
break;
case 6: printf("The grade is D.\n");
break;
case 7: printf("The grade is C.\n");
break;
case 8: printf("The grade is B.\n");
break;
case 9: printf("The grade is A.\n");
break;
case 10: printf("The grade is A.\n");
break;
}
}
return 0;
}