I am trying to create a program that will allow a user to input 5 letter grades and then it outputs the total grade points and the grade point average. I am having trouble converting the letter grade from the user into a value. If the user inputs "A" then it should equal 4, "B" should equal 3, etc. Any help is greatly appreciated. Thank you.
This is what I have so far. I have edited it from time of the original post now I am just not getting a correct GPA or total grade points. If I put "A" in five times I should get total grade point = 20 and GPA = 4.0 but instead I am getting 35 and GPA= 7.0.... please help me! THank You!
// VARIABLES
char grade; // INPUT - Grade user inputs.
int gradePoints=0; // CALC & OUTPUT - Total grade points.
float gradeAvg; // CALC & OUTPUT - Grade point average.
int count; // PROCESS - Loop will run as count is less
// than or equal to 5.
//INPUT & PROCESSIONG - Program will convert letter grades to grade
// points, calculate grade points, and calculate
// grade point average.
cout << left;
cout << "TEST #1: " << endl; // Title and test number.
You're assigning values to 'grade' in the if statements for grades C, D and F, which is affecting your overall grade.
You need to use the == operator for these statements. Additionally, I would if an if-else block here (or a switch statement), rather than a bunch of individual ifs.
Wow I totally forgot about the (==). I only used that for the first comparison. I was up until 2:00 am trying to figure it out. Much needed rest and your help definitely cleared things up. I switched the if-then statements to if-then-else. I have not covered and can not use a switch statement. Thanks again for the help. I really appreciate it. Here is my final code... any other suggestions?
// CONSTANTS - Assigning grades to variables in order to compare
// input from user to these constants and convert
// letter grade into grade points.
const char gradeA='A';
const char gradeB='B';
const char gradeC='C';
const char gradeD='D';
const char gradeF='F';
// VARIABLES
char grade; // INPUT - Grade user inputs.
int gradePoints=0; // CALC & OUTPUT - Total grade points.
float gradeAvg; // CALC & OUTPUT - Grade point average.
int count; // PROCESS - Loop will run as count is less
// than or equal to 5.
//INPUT & PROCESSIONG - Program will convert letter grades to grade
// points, calculate grade points, and calculate
// grade point average.
cout << left;
cout << "TEST #1: " << endl; // Title and test number.