LETTER GRADE
Problem Description
At a particular university, letter grades are mapped to grade points in the following manner:
Letter Grade points
A+ 4.0
A 4.0
A- 3.7
B+ 3.3
B 3.0
B- 2.7
C+ 2.3
C 2.0
C- 1.7
D+ 1.3
D 1.0
F 0
Write a program that begins by reading a letter grade from the user.
Then your program should compute and display the equivalent number of grade points.
Ensure that your program generates an appropriate error message if the user enters an invalid letter grade.
CODING ARENA
#include <stdio.h>
int main()
{
char s[5];
scanf("%s",s);
if(s[0]=='A')
{
if(s[1]=='+')
printf("4.0");
else if(s[1]=='-')
printf("3.7");
else if (s[1]=='\0')
printf("4.0");
}
if(s[0]=='B')
{
if(s[1]=='+')
printf("3.3");
else if(s[1]=='-')
printf("3.0");
else if(s[1]=='\0')
printf("3.0");
}
if(s[0]=='C')
{
if(s[1]=='+')
printf("2.3");
else if(s[1]=='-')
printf("1.7");
else if(s[1]=='\0')
printf("2.0");
}
if(s[0]=='D')
{
if(s[1]=='+')
printf("1.3");
else if(s=='\0')
printf("1.0");
}
else
printf("0");
return 0;
}
Test Case 1
Input (stdin)B+
Expected Output
3.3
Test Case 2
Input (stdin)D+
Expected Output
1.3
Post this for python
ReplyDelete