Calculating GPA

hi! this is a school project and i need help on making the GPA 2.333333.
i think the problem lies within the process data segment where it says GPA = ..... but i dont know what to do or how to fix it. can someone please help me??


#include <iostream>
#include <stdio.h>
#include <string>

using namespace std;

int main()
{

/********** VARIABLE DECLARATION SEGMENT **********/

int CrHrs1,CrHrs2,CrHrs3,CrHrs4; // number of credit hours for 4 courses
int ValPt1,ValPt2,ValPt3,ValPt4; // number of value points earned
int TotalValue; // total value points for 4 courses
int TotalHours; // total credit hours for 4 courses
double GPA; // grade point average for 4 courses


/*********** ENTER DATA SEGMENT **********/


cout << "This program will compute your GPA for the current semester" << endl;
cout << "For each of your four courses enter CREDIT HOURS followed" << endl;
cout << "by grade point VALUE. Use A=4, B=3, C=2, D=1, F=0\n";
cout << "Press <SPACE> between each data entry\n" << endl;
cout << endl;
cout << "Enter Course 1 data ===>> ";
cin >> CrHrs1 >> ValPt1;
cout << "Enter Course 2 data ===>> ";
cin >> CrHrs2 >> ValPt2;
cout << "Enter Course 3 data ===>> ";
cin >> CrHrs3 >> ValPt3;
cout << "Enter Course 4 data ===>> ";
cin >> CrHrs4 >> ValPt4;


/********* PROCESS DATA SEGMENT **********/

TotalValue = ValPt1 + ValPt2 + ValPt3 + ValPt4;
TotalHours = CrHrs1 + CrHrs2 + CrHrs3 + CrHrs4;
GPA = (TotalValue + TotalHours) /4;

/********** DISPLAY DATA SEGMENT **********/

cout << endl << endl;
cout << "Course 1: " << CrHrs1 << " Hours, " << ValPt1 << " Value Points" << endl;
cout << "Course 2: " << CrHrs2 << " Hours, " << ValPt2 << " Value Points" << endl;
cout << "Course 3: " << CrHrs3 << " Hours, " << ValPt3 << " Value Points" << endl;
cout << "Course 4: " << CrHrs4 << " Hours, " << ValPt4 << " Value Points" << endl;
cout << endl;
cout << "Current GPA: " << GPA << endl;

system("pause");
}
In C++, an int divided by an int gives you an int.

5/4 gives you 1
15/4 gives you 3

(TotalValue + TotalHours) /4; is an int divided by an int, so you get back an int. No decimal places.


okay so under the variable declaration segment i kept the first two as int and changed the last three to double. it seems like that works. also how do i calculate the GPA to where it can give me 2.333333?
Topic archived. No new replies allowed.