GPA Calculator in C++
Posted by Samath
Last Updated: January 17, 2024

Grade point average (GPA) is a measure of a student's academic achievement at an educational institution. A student's GPA is calculated by dividing the total number of grade quality points they earn by the total number they attempt. The result, rounded off to two decimal places, is the student's GPA.

This GPA calculator will prompt the user to enter a student's grades.  After each grade is entered by the user, the program will give the use the option to continue entering grades or to stop entering grades and calculate the GPA.

Code:

#include <iostream>

using namespace std;
int main(int argc, char *argv[])
{

	const double A = 4.0;
    const double A_MINUS = 3.67;
	const double B_PLUS = 3.33;
	const double B = 3.0;
	const double B_MINUS = 2.67;
	const double C_PLUS = 2.33;
	const double C = 2.0;
	const double C_MINUS = 1.67;
	const double D = 1.00;
	const double F = 0.0;
	
	string lettergrade;
 	double credit;
    double caltimes = 0;
    double totalcal = 0;
    double totalcredit = 0;
    double finalgpa = 0;
    int option;
  
 	for(;;)
    {           
        cout<<"\nEnter letter grade: ";
        cin>>lettergrade;
        cin.ignore();
        cout<<"Enter the course credit: ";
        cin>>credit;
    
			   
		if(lettergrade == "a" || lettergrade == "A")
		{
			caltimes = credit * A;
		}
		else if(lettergrade == "a-" || lettergrade == "A-")
		{
			caltimes = credit * A_MINUS;
		}
		else if(lettergrade == "b+" || lettergrade == "B+")
		{
			caltimes = credit * B_PLUS;
		}
		else if(lettergrade == "b" || lettergrade == "B")
		{
			caltimes = credit * B;
		}
		else if(lettergrade == "b-" || lettergrade == "B-")
		{
			caltimes = credit * B_MINUS;
		}
		else if(lettergrade == "c+" || lettergrade == "C+")
		{
			caltimes = credit * C_PLUS;
		}
		else if(lettergrade == "c" || lettergrade == "C")
		{
			caltimes = credit * C;
		}
		else if(lettergrade == "c-" || lettergrade == "C-")
		{
			caltimes = credit * C_MINUS;
		}
		else if(lettergrade == "d" || lettergrade == "D")
		{
			caltimes = credit * D;
		}
		else if(lettergrade == "f" || lettergrade == "F")
		{
			caltimes = credit * F;
		}	   
		else
		{
			cout<<"Invaild Input...";
		}
	
	             
          totalcredit = totalcredit + credit;
          totalcal = totalcal + caltimes;
          
		  cout<<"Do you want to enter another grade (1 - Yes, 2 - no): ";
		  cin>>option;
		  if(option == 1)
		  {
		  	continue;
		  }
		  else
		  {
		  	break;
		  }      
 	}
                
          finalgpa = totalcal/totalcredit;
          cout<<"Student's GPA: "<<finalgpa<<"\n";
    
	
	return 0;
}

 

Related Content
GPA Calculator using C#
GPA Calculator using C#
Samath | Jan 01, 2021
Simple GPA calculator in Java
Simple GPA calculator in Java
Samath | Jan 17, 2024
GPA Calculator using Python
GPA Calculator using Python
Samath | Jan 20, 2024
C Program that calculates GPA
C Program that calculates GPA
Samath | Jan 20, 2024
Simple Calculator using C#
Simple Calculator using C#
Samath | Dec 30, 2020
Calculator Program in Java
Calculator Program in Java
Samath | Jan 07, 2021
Simple C++ Calculator
Simple C++ Calculator
Samath | Jan 05, 2017
Simple Calculator using Python
Simple Calculator using Python
Samath | Jan 09, 2017
Scientific Calculator using C#
Scientific Calculator using C#
Samath | Jan 08, 2021