Beruflich Dokumente
Kultur Dokumente
Join us in building a kind, collaborative learning community via our updated Code of Conduct.
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
int main ()
{
char grade;
int value;
cout << "Enter letter grade : " ;
cin >> grade;
switch(grade)
{
case 'A' : value = 4;
break;
case 'B' : value = 3;
break;
case 'C' : value = 2;
break;
case 'D' : value = 1;
break;
case 'E' : value = 0;
break;
default : cout << "Wrong input " << endl;
break;
}
https://stackoverflow.com/questions/16188085/grading-system-in-c 1/6
8/31/2018 if statement - Grading system in C++ - Stack Overflow
3 Answers
char a[3];
float m,n;
cin>>a;
if(a[1]=='+')
m=0.3;
else if (a[1]=='-')
m=-0.3;
else
m=0;
switch(a[0])
{ to learn, share knowledge, and build your career.
This site uses cookies//Assign
to deliverthe
ourvalue
services and to show you relevant ads and job listings. By using our site, you
of n as 4,3,2,1 d
acknowledge that you
} have read and understand our , , and our . Your use of
cout<<n+m;
Stack Overflow’s Products and Services, including the Stack Overflow Network, is subject to these policies and terms.
https://stackoverflow.com/questions/16188085/grading-system-in-c 2/6
8/31/2018 if statement - Grading system in C++ - Stack Overflow
uint value = 0;
char grade_letter = grade[0];
switch (grade_letter) {
// assign value as appropriate
}
to learn, share knowledge, and build your career.
This site uses cookies to deliver our services and to show you relevant ads and job listings. By using our site, you
acknowledge that Then, if the
you have second
read character
and understand exists,
our , , and our . Your use of
check if it's a + or a - and modify the
Stack Overflow’s Products and Services, including the Stack Overflow Network, is subject to these policies and terms.
https://stackoverflow.com/questions/16188085/grading-system-in-c 3/6
8/31/2018 if statement - Grading system in C++ - Stack Overflow
if (grade.length() > 1) {
char modifier = grade[1];
switch (modifier) {
case '+': value += 0.3;
// etc.
}
}
switch(grade)
{
case "A" : value = 4;
break;
case "A+" : value = 4.3;
break;
case "A-" : value = 3.7;
break;
case "B" : value = 3;
break;
case "B+" : value = 3.3;
break;
case "B-" : value = 2.7;
break;
case "C" : value = 2;
break;
case "C+" : value = 2.3;
break;
case "C-" : value = 1.7;
break;
case "D" : value = 1;
break;
case "D+" : value = 1.3;
break;
case "D-" : value = 0.7;
break;
case "F" : value = 0;
break;
default : cout << "Wrong input " <
break;
}
https://stackoverflow.com/questions/16188085/grading-system-in-c 6/6