Hello, I've been programming with C++ for only several weeks now, but I have come across a practice problem that has given me trouble.
The objectives: collect data from a student including: his major (CIS or Math), last name, number of credits completed, GPA, and tuition paid.
Then calculate and print: Average GPA,
total tuition paid,
average tuition paid,
average number of credits taken by all students,
name of student with highest GPA along with GPA,
and name of Math student with highest GPA along with GPA.
I'm not supposed to code arrays. This is practice that is similar to an exam I'll have soon.
I've attempted the first four calculations below; where is my code incorrect for these steps? Also, I need help on what code to use to display the highest GPA from the data. Any help on this work is appreciated.
This is what I have so far:
#include <iostream>
#include <string>
using namespace std;
int main()
{
int major;
string lastname;
float credits;
float totalcredits =0;
float averagecredits;
float gpa;
float totalgpa =0;
float averagegpa;
float tuition;
float totaltuition =0;
float averagetuition;
float maxgpa;
char doagain = 'y';
int count;
count = 0;
while (doagain == 'y');
{
cout << "Enter your major (0=CIS, 1=Math): ";
cin >> major;
cout << "Enter your last name: ";
cin >> lastname;
cout << "Enter the number of credits completed: ";
cin >> credits;
cout << "Enter your gpa: ";
cin >> gpa;
cout << "Enter your tuition: ";
cin >> tuition;
totalcredits = totalcredits + credits;
totaltuition = totaltuition + tuition;
totalgpa = totalgpa + gpa;
cout << "Do you want to continue y/n";
cin >> doagain;
count++;
}
cout << "The Total Tuition is: " << totaltuition <<endl;
if (count > 0)
{
averagetuition = totaltuition/count;
cout << "The Average Tuition is: " << averagetuition <<endl;
}
if (count > 0)
{averagegpa = totalgpa/count;
cout << "The Average gpa is: " << averagegpa <<endl;
}
if (count > 0)
{averagecredits = totalcredits/count;
cout << "The Average number of credits taken is: " <<averagecredits <<endl;
}
return 0;
}