Apr 20, 2013 at 8:20pm UTC
I am a newbie trying to write a program where I can input a letter grade and gives me a grade point as the output. But I am having a hard time getting the program to read the "+" and "-" of the grades.
I would really appreciate the help!
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
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
char letterGrade;
int i = 0;
cout << "Grade: " ; cin >> letterGrade;
if (letterGrade == 'A' )
{
cout << "4.0" ;
}
else if (letterGrade == 'A-' )
{
cout << "3.7" ;
}
else if (letterGrade == 'B+' )
{
cout << "3.3" ;
}
else if (letterGrade == 'B' )
{
cout << "3.0" ;
}
else if (letterGrade == 'B-' )
{
cout << "2.7" ;
}
cout << " " << endl;
cout << "Press any key to exit: " << endl;
cin >> i;
return 0;
}
Last edited on Apr 20, 2013 at 8:32pm UTC
Apr 20, 2013 at 8:28pm UTC
cin only gets a single character input. What you want to use is getline(cin, letterGrade);
Apr 20, 2013 at 8:29pm UTC
Use double quotes around your constants instead of single quotes; single quotes are for single characters only, not strings as you are using here.
Apr 20, 2013 at 8:36pm UTC
Thank You very much!!! Problem Solved!