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.
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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
#include <iostream>
#include <iomanip>
#include <cmath>
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.