blob: b22cd661067a2652b1e84035cf123b2f66a0427a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
/*File: switchgrade.c
This program reads a grade from the screen and prints the corresponding numerical value of the score.*/
#include <stdio.h>
int main()
{
char grade;
double score;
printf("Enter a grade [A,B,C,D,F]: ");
scanf(" %c",&grade);
//Force all characters to be uppercase
if(grade>=97)
{
grade = grade-32;
}
switch(grade)
{
case 'A':
score += 1.0;
case 'B':
score += 1.0;
case 'C':
score += 1.0;
case 'D':
score += 1.0;
case 'F':
break;
default:
score = -1;
printf("Invalid grade %c\n",grade);
break;
}
if(score != -1)
{
printf("The score for the grade %c is %.2f\n",grade,score);
}
return 0;
}
|