### GPA calculator

*Write a program using a switch statement that calculates your last semester GPA. A grade of A is worth 4 points; B is worth 3 points, and so on.
 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475`` ``````#include #include #include using namespace std; int main() { int grade; int counter = 0; int aValue = 0; int bValue = 0; int cValue = 0; int dValue = 0; int fValue = 0; double total = 0; cout << "Enter last semesters grades: " << endl; while ( (grade = cin.get() ) != EOF ) { switch (grade) { case 'A': case 'a': aValue += 4; counter += 1; break; case 'B': case 'b': bValue += 3; counter += 1; break; case 'C': case 'c': cValue += 2; counter += 1; break; case 'D': case 'd': dValue +=1; counter += 1; break; case 'F': case 'f': fValue += 0; counter += 1; break; case '\n': case ' ': break; default: cout << "Incorrect letter grade" << endl; break; } } total = aValue + bValue + cValue + dValue + fValue; cout << setprecision(2) << fixed << total/counter << endl; system ("pause"); return 0; }``````
Topic archived. No new replies allowed.