Write a program that translates a letter grade into a number grade. Letter grades are A, B, C, D, and F, possibly followed by + or -. Their numeric values are 4, 3, 2, 1, and 0. There is no F+ or F-. A + increases the numeric value by 0.3, a – decreases it by 0.3. However, an A+ has value 4.0. Enter a letter grade: B- The numeric value is 2.7.
ANS:
I had written the code in C language:
#include <stdio.h>
int main()
{
float a;
char f[2];
printf("Enter a letter grade:");
scanf("%c",f);
scanf("%c",(f+1));
if('A'==f[0]){
if('-'==f[1] ){
a=4-0.3;
printf("The numeric value is %f",a);
}
else{
a=4;
printf("The numeric value is %f",a);
}
}
else if ('B'==f[0]){
if('+'==f[1]){
a=3+0.3;
printf("The numeric value is %f",a);
}
else if ('-'==f[1]){
a=3-0.3;
printf("The numeric value is %f",a);
}
else{
a=3;
printf("The numeric value is %f",a);
}
}
else if ('C'==f[0]){
if('+'==f[1]){
a=2+0.3;
printf("The numeric value is %f",a);
}
else if ('-'==f[1]){
a=2-0.3;
printf("The numeric value is %f",a);
}
else{
a=2;
printf("The numeric value is %f",a);
}
}
else if ('D'==f[0]){
if('+'==f[1]){
a=1+0.3;
printf("The numeric value is %f",a);
}
else if ('-'==f[1]){
a=1-0.3;
printf("The numeric value is %f",a);
}
else{
a=1;
printf("The numeric value is %f",a);
}
}
else if('F'==f[0]){
if('+'==f[1]){
printf("There is no F+, you enter a wrong letter grade.");
}
else if ('-'==f[1]){
printf("There is no F-, you enter a wrong letter grade.");
}
else{
a=0;
printf("The numeric value is %f",a);
}
}
else
printf("YOU ENTER A WRONG LETTER GRADE.");
return 0;
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 3 images