I have written the following code to try to get my GPA calculator program to work. I am not allowed to use arrays. I only know what I am doing from the videos I have watched on youtube and the slideshows that we get from our instructor. Unfortunately, the slideshow this week does not cover using While and If statements.
Any help would be appreciated.
The goal of this is to find out the GPA of various courses.
Each course has a specific number of credit hours.
I am to prompt for a grade letter. The grade letter gets converted to a number letter, and then I am supposed to figure out the GPA.
//
#include <iostream>
using namespace std;
void Error()
{
cout << "Not a valid letter grade. Please check your letter grade and try again." << endl;
}
//need to find the grade point average for the semester
void main()
{
float Sum = 0.00f;
int Counter = 0;
char LetterGrade = 0;
float number = 0.00f;
//GetLetterGrade Module
cout << "Enter Letter Grade: ";
cin >> LetterGrade;
while(LetterGrade != 0000)
{
Sum += LetterGrade;
Counter += 1;
cout << "Enter Letter Grade: ";
cin >> number;
}
//Convert Letter Grades to Numeric values
switch(LetterGrade)
{
case 'f':
case 'F': number = 0.0;
cout << "0.0";
break;
case 'd':
case 'D': number = 1.0;
break;
case 'c':
case 'C': number = 2.0;
break;
case 'b':
case 'B': number = 3.0;
break;
case 'a':
case 'A': number = 4.0;
break;
default: Error();
break;
}
float Average = 0.00f;
//CalcAvgTemp Module
Average = Sum/Counter;
//PrintAvgTemp Module
cout << "The Grade Point Average is " << Average << endl;
}