### Need some quick help. (structs)

can anyone tell me why my STU.GPA calculations always end up as "114"

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178`` ``````// ------------------------------------------------------------------ // File name: academicsA.cpp // Assign ID: PROG3a_Academics // Due Date: 02/02/13 at 11pm // // Purpose: Give student experience working with user-defined struct data types. // // Author: bfields Byron Fields // // ------------------------------------------------------------------ #include #include using namespace std; int main() { // ---------------------------------------------------------------------- // Declare variables // ---------------------------------------------------------------------- int Acount = 0; int Bcount = 0; int Ccount = 0; int Dcount = 0; int Fcount = 0; int GPAa = 0; struct STUDENT { long StudID; // 9-digit number. string Last; string First; int CumHours; float GPA; }; STUDENT STU; struct ENROLLMENT { long StudID; string Semester; string CrsPrefix; int CrsNumber; int CreditHrs; char Grade; }; ENROLLMENT E1, E2, E3; //-| ---------------------------------------------------------------------- //-| Print the copyright notice declaring authorship. //-| ---------------------------------------------------------------------- cout << endl << "(c) 2013, bfields Byron Fields" << endl << endl; //-| ---------------------------------------------------------------------- //-| 1. Read student data into a STUDENT record. //-| ---------------------------------------------------------------------- cin >> STU.StudID >> STU.Last >> STU.First; // Input data sequence: StudID, Lastname, Firstname //-| ---------------------------------------------------------------------- //-| 2. Read three ENROLLMENT records. //-| ---------------------------------------------------------------------- cin >> E1.Semester >> E1.CrsPrefix >> E1.CrsNumber >> E1.CreditHrs >> E1.Grade; // Input data sequence: Semester CrsPrefix CrsNumber CreditHrs Grade E1.StudID = STU.StudID; // NOTE: Copy the StudID from the STUDENT record into each ENROLLMENT record. cin >> E2.Semester >> E2.CrsPrefix >> E2.CrsNumber >> E2.CreditHrs >> E2.Grade; // Input data sequence: Semester CrsPrefix CrsNumber CreditHrs Grade E2.StudID = STU.StudID; // NOTE: Copy the StudID from the STUDENT record into each ENROLLMENT record. cin >> E3.Semester >> E3.CrsPrefix >> E3.CrsNumber >> E3.CreditHrs >> E3.Grade; // Input data sequence: Semester CrsPrefix CrsNumber CreditHrs Grade E3.StudID = STU.StudID; // NOTE: Copy the StudID from the STUDENT record into each ENROLLMENT record. //-| ---------------------------------------------------------------------- //-| 3. Compute the #hours student has taken. //-| ---------------------------------------------------------------------- STU.CumHours += E1.CreditHrs + E2.CreditHrs + E3.CreditHrs; //-| ---------------------------------------------------------------------- //-| 4. Compute the GPA based on course grade and credit hours. //-| ---------------------------------------------------------------------- if(E1.Grade == 'A') { Acount += 4 * E1.CreditHrs; } else if(E1.Grade == 'B') Bcount += 3 * E1.CreditHrs; else if(E1.Grade == 'C') Ccount += 2 * E1.CreditHrs; else if(E1.Grade == 'D') Dcount += 1 * E1.CreditHrs; else Fcount += 1; GPAa += (Acount + Bcount + Ccount + Dcount); Acount = 0; Bcount = 0; Ccount = 0; Dcount = 0; if(E2.Grade == 'A') { Acount += 4 * E2.CreditHrs; } else if(E2.Grade == 'B') Bcount += 3 * E2.CreditHrs; else if(E2.Grade == 'C') Ccount += 2 * E2.CreditHrs; else if(E2.Grade == 'D') Dcount += 1 * E2.CreditHrs; else Fcount += 1; GPAa += (Acount + Bcount + Ccount + Dcount); Acount = 0; Bcount = 0; Ccount = 0; Dcount = 0; if(E3.Grade == 'A') { Acount += 4 * E3.CreditHrs; } else if(E3.Grade == 'B') Bcount += 3 * E3.CreditHrs; else if(E3.Grade == 'C') Ccount += 2 * E3.CreditHrs; else if(E3.Grade == 'D') Dcount += 1 * E3.CreditHrs; else Fcount += 1; GPAa += (Acount + Bcount + Ccount + Dcount); STU.GPA = GPAa/STU.CumHours; //-| ---------------------------------------------------------------------- //-| 5. Print the STUDENT record in the format below: //-| ---------------------------------------------------------------------- cout << left << setw(10) << "STUDENT:" << left << setw(9) << STU.StudID << right << setw(12) << STU.First << ' ' << left << setw(12) << STU.Last << right << setw(3) << STU.CumHours << right << setw(4) << fixed << setprecision(3) << STU.GPA << endl; //-| ---------------------------------------------------------------------- //-| 6. Print the three ENROLLMENT records in the format below: //-| //-| COURSES TAKEN <== Header //-| ============= <== Header //-| <== Header //-| STUDENTID^^SEMESTER^^PREFIX^^NUMBER^^HOURS^^GRADE <== Header //-| =========^^========^^======^^======^^=====^^===== <== Header //-| xxxxxxxxx xxxxxxxx xxx xxxx xx x <== Data //-| xxxxxxxxx xxxxxxxx xxx xxxx xx x //-| xxxxxxxxx xxxxxxxx xxx xxxx xx x //-| ---------------------------------------------------------------------- cout << "COURSES TAKEN" << endl; cout << "=============" << endl; cout << endl; cout << "STUDENTID SEMESTER PREFIX NUMBER HOURS GRADE" << endl; cout << "========= ======== ====== ====== ===== =====" << endl; cout << left << setw(9) << E1.StudID << " " << left << setw(8) << E1.Semester << " " << left << setw(6) << E1.CrsPrefix << " " << left << setw(6) << E1.CrsNumber << " " << right << setw(5) << E1.CreditHrs << " " << E1.Grade << endl; cout << left << setw(9) << E2.StudID << " " << left << setw(8) << E2.Semester << " " << left << setw(6) << E2.CrsPrefix << " " << left << setw(6) << E2.CrsNumber << " " << right << setw(5) << E2.CreditHrs << " " << E2.Grade << endl; cout << left << setw(9) << E3.StudID << " " << left << setw(8) << E3.Semester << " " << left << setw(6) << E3.CrsPrefix << " " << left << setw(6) << E3.CrsNumber << " " << right << setw(5) << E3.CreditHrs << " " << E3.Grade << endl; //-| ---------------------------------------------------------------------- //-| Print the copyright notice declaring authorship again. //-| ---------------------------------------------------------------------- cout << endl << "(c) 2013, bfields Byron Fields" << endl << endl; return 0; }//main ``````
Don't forget to add the string library.

Consider using a switch statement when checking for grades:
 ``12345678`` ``````switch(E3.Grade) { case 'A': Acount += 4 * E3.CreditHrs; break; case 'B': etc..``````

I tried the switch statements and it gave me "104" this time.

Do you think there is something off about my calculations?
Topic archived. No new replies allowed.