I feel like I am getting very close! I just need a little more help :)

Okay, so I need to write a program that will take in 5 letter grades, and will convert them to grade points. Then I need to output the sum of the grade points, and the average GPA of the 5 grades. My teacher wants us to use nested if-then-else statements. For the code, I have this so far:
``````int main()
{

float gradesum; //The total value of the 5 grade points combined -
//CALC & OUTPUT

float gradeTotal; //The average of the 5 grade point values - CALC &
//OUTPUT

//Variables - These are the 5 prompts that are given to the user for
// the grade input, and then they are stored into their
// values
cout << "Enter Letter Grade #1: " << endl;

cout << "Enter Letter Grade #2: " << endl;

cout << "Enter Letter Grade #3: " << endl;

cout << "Enter Letter Grade #4: " << endl;

cout << "Enter Letter Grade #5: " << endl;

// their numeric value. The grades are then totaled, and are
// averaged.

{
}

else
{

{
}
else
{

{
}
else
{
{
}
else
{
{
}
else
{
cout << "Invalid grade" << endl;
}

//Output- The total grade points are outputed, followed by the average of
// the grade points, which is the average of the grade points

cout << "GPA :" << gradeTotal;

``````

I am not getting the expected output though. Do I need to use a For Loop so it can check all 5 grades? Can someone help me complete this? Thank you so much!

My expected output is to enter: C,B,A,D,C

and result with:

GPA: 2.40

• Your program is only testing one grade for letter 'A', another grade for 'B' etc . You need to check each grade for 'A', 'B' , 'C', 'D' and 'F'. The best way to do that and avoid duplication of code (5 sets of if/then/else statements) is to write a function that returns the numeric grade.
``````int checkgrade(char g)
{
if( g == 'A')
return 100;
else if( g == 'B')

etc.
}
``````
• //try this

//@dragon functions are above rjh9136, but i do agree

if (tempChar == 'A')

else if (tempChar == 'B')

......
• This would be easier with a loop yes:
``````//Christopher D'Angelo (www.mathhead200.com)
//Use this code ONLY as a guide!

if( grade == 'A' ) return 4;
if( grade == 'B' ) return 3;
if( grade == 'C' ) return 2;
if( grade == 'D' ) return 1;
return -1; //if no valid grade was found
}

void kill() {
exit(1);
}

int main() {
const int N = 5; //num of grades
int sum = 0;
for( int i = 0; i < N; i++ ) {
cout << "Enter grade " << i << ": ";
kill();
if( num < 0 )
kill();
sum += num;
}
cout << "GPA = " << (sum / N) << endl;
return 0;
}
``````
• You have to do this for every grade:
``````if (grade1 == 'A')
{
}

else
{

{
}
else
{

{
}
else
{
{