Hello, I am trying to make a GPA calculator, the code below works fine and the output is also fine the only problem is if the GPA is 4.0 or 3.0 or 2.0 or 1.0 it gives me output as 4, 3, 2, 1 i had used variable as float then also I am having this problem is the GPA is 3.5 then it gives me output as 3.5 the only problem is with round numbers such as 3.0 or 4.0....
_____________________________________________________
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char *argv[])
{
// CODE STARTS HERE
string HEADING = "ttttGPA CALCULATOR";
cout << HEADING<<endl;
int x;
float GPA, TotalHrs = 0, GradeEqaPoints = 0,CrHours;
char Grade, A, B, C, D, E, F;
char choice = 'Y';
while (choice == 'Y' || choice == 'y')
{
cout << "nENTER YOUR GRADE ---> ";
cin >> Grade;
cout << "nENTER CREDIT HOUR FOR THE GRADE ENTERED ---> ";
cin >> CrHours;
if
(Grade == 'A' || Grade == 'a')
GradeEqaPoints = GradeEqaPoints + 12;
if
(Grade == 'B' || Grade == 'b')
GradeEqaPoints = GradeEqaPoints + 9;
if
(Grade == 'C' || Grade == 'c')
GradeEqaPoints = GradeEqaPoints + 6;
if
(Grade == 'D' || Grade == 'd')
GradeEqaPoints = GradeEqaPoints + 3;
if
(Grade == 'F' || Grade == 'f')
GradeEqaPoints = GradeEqaPoints + 0;
TotalHrs = TotalHrs + CrHours ;
GPA = GradeEqaPoints/TotalHrs;
{
cout <<endl;
cout << "nDO YOU WISH TO CONTINUE? (Y/N) ---> ";
cin >> choice;
cout << endl;
}
}
cout << "ntttTOTAL CREDIT HOURS TAKEN FOR THIS SEMISTER ---> "<<TotalHrs;
cout << endl;
cout << "ntttTOTAL QUALITY POINTS ---> "<<GradeEqaPoints;
cout<< endl;
cout << "ntttYOUR CUMULATIVE GPA ---> "<<GPA;
cout << endl;
{
cout << "nENTER (X) TO EXIT --> ";
cin >> x;
cout << endl;
return (0);
}
}
// CODE ENDS HERE