in the C language Write a program that assigns test score grades. The program\'s
ID: 3801161 • Letter: I
Question
in the C language Write a program that assigns test score grades. The program's input should be a series of test scores of type int. Have the program read each score and print either the corresponding grade or an appropriate error message. The program is to continue until end-of-file. If invalid character data is entered, you will need to flush the invalid characters so that test scores can continue to be entered until end-of-file.
please write the program that is similar to the code below
while((r=scanf("%i" & score))!=EOF)
{
if(r==0) // invalid char
{
printf("");
while(getChar()!=' ');
}
else
switch(score)
}
Assume the following grading scale:
9 - 10 A
8 B
7 C
6 D
0 - 5 F
Use a switch statement to assign or print the appropriate grade.
Run your program using the following input:
1. All of the values between 0 and 10, inclusive
2. A negative value
3. A value greater than 10
4. A character value
Run the program with a valid value after all of these error cases to verify that the bad data was flushed correctly.
USE the correct use of local variables, local prototypes, and parameter passing
Explanation / Answer
//Include basic header files
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int r,score;
printf(' Enter Score:);
while((r=scanf("%d",&score))!=EOF)
{
if(r==0)
{
printf("");
while(getChar()!=' ');
}
else
{
switch(score)
{
case 10:
case 9: printf(" Your Grade is:A");
break;
case 8: printf(" Your Grade is:B");
break;
case 7: printf(" Your Grade is:C");
break;
case 6: printf(" Your Grade is:D");
break;
case 5:
case 4:
case 3:
case 2:
case 1:
case 0: printf(" Your Grade is:F");
break;
default: if(score<0)
printf(" Score cannot be a negative number");
if(score>10)
printf(" Score cannot be greater than 10");
if((score>=65&&score<=123)
printf(" Score cannot be a character");
}
}
}
getch();
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.