### Print the name of the student with the Highest GPA along with the GPA

Need help printing the name of a user created student with the user created GPA with the Highest GPA after his/her name.

#include <iostream>
#include <string>
using namespace std;
int main()
{
double gpa,gpa_average, gpa_total=0,gpa_high;
//INITIALIZE TOTAL TUITION TO 0
double tuition, tuition_total=0 , tuition_average, credit_average;
//CREATED A COUNT TO COUNT THE NUMBER OF STUDNETS
int credits,credit_total=0, CIS_count=0, Math_count=0,F_count=0,So_count=0,J_count=0,Se_count=0,count=0, count2=0, count3=0;
string lastname, high_lastname=" ";
string major;
//while loop
string more_info = "yes";

while(more_info=="yes")
{
//ENTER
cout<<endl<<endl<<"Enter students's last name ";
cin>>lastname;
cout<<"Enter student's major (CIS or Math) ";
cin>>major;
cout<<"Enter number of credits ";
cin>>credits;
cout<<"Enter gpa ";
cin>>gpa;
cout<<"Enter amount of tuition paid ";
cin>>tuition;

//YOU HAVE TO COUNT THE STUDENTS
count=count+1;

count2=count2+1;

count3=count3+1;

//ADD THE TUITION FIRST WITHIN THE LOOP
//if (tuition=0)
// tuition++;
tuition_total=tuition_total+tuition;
credit_total=credit_total+credits;
gpa_total=gpa_total+gpa;

if (major=="CIS")
CIS_count=CIS_count+1;
else
Math_count=Math_count+1;

if (credits < 30)
F_count=F_count+1;
else

if (credits >= 31 && credits < 60)
So_count=So_count+1;
else

if (credits >= 61 && credits <= 90)
J_count=J_count+1;
else

if(credits > 90)
Se_count=Se_count+1;

if (gpa>

//end of while loop
cout<<"Enter more Student info yes/no ";

cin>>more_info;
}

//DO THE AVERAGE CALCULATION OUTSIDE OF THE LOOP
tuition_average=tuition_total/count;
credit_average=credit_total/count2;
gpa_average=gpa_total/count3;

cout<<endl<<endl;
//YOU ARE NOT PRINTING EACH OF THE STUDENT NAMES AND MAJORS
//cout<<"Student name "<<lastname<<endl;
//cout<<"S Major "<<major<<endl<<endl;
cout<<"number of credits "<<credits<<endl;
cout<<"The total number CIS majors = "<<CIS_count<<endl;
cout<<"The total number Math majors = "<<Math_count<<endl;
cout<<"The total number Freshmen = "<< F_count<<endl;
cout<<"The total number Sophmores = "<<So_count<<endl;
cout<<"The total number Juniors = "<< J_count<<endl;
cout<<"The total number Seniors = "<<Se_count<<endl;
//PINT THE TOTAL AND AVERAGE TUITION
cout<<"Total tuition paid "<<tuition_total<<endl<<endl;
cout<<"Average tuition "<<tuition_average<<endl;
cout<<"Average credits "<<credit_average<<endl;
cout<<"Average gpa "<<gpa_average<<endl;
cout<<"Student with the highest GPA "<<lastname<<cout<<"GPA "<<high_gpa<<endl;
system("pause");
return 0;
}

Last edited on
Topic archived. No new replies allowed.