This next practice problem has me implementing functions into code I completed before calculating data about students. I'm getting an error message, and am looking for where my problem(s) are.

Objectives of this problem:
-Collect data from user: major, last name, credits completed, gpa, tuition paid.
-Call a function to read all the data and pass it back by reference
-Call functions to calculate average GPA, average tuition, and average credits and pass them back by value to main program
-Call function to print: name of student with highest GPA and the GPA (do same for math students only and CIS students only)
-Call function to print number of freshmen, sophomores, juniors, and seniors (determined by number of credits)

Thanks in advance for any help or advice.

This is what I have so far:

#include <iostream>
#include <string>
using namespace std;
void getdata(int &major, string &lastname, float &credits, float &gpa, float &tuition, int &senior, int &freshman, int &sophomore, int &junior, float &totaltuition, float &totalcredits, float &totalgpa, float &maxgpa, float &maxmathgpa, float &maxcisgpa, string &lastname, string &newlastname, string &mathlastname, string &cislastname);
float compute(float avgtuit, float totaltuit, float tuit, int cnt);
float compute(float avggp, float totalgp, float gp, int cnt);
float compute(float avgcrdts, float totalcrdts, float crdts, int cnt);
void printdata(float avggp, float totaltuit, float avgtuit, float avgcrdts);
void printdata(string newlstnm, float maxgp, string mathlstnm, float mathgp, string cilstnm, float cisgp);
void printdata(int frshmn, int sphmr, int jnr, int snr);

int main()
{
    int major;
    int freshman =0;
    int sophomore =0;
    int junior =0;
    int senior =0;
    string lastname;
    string newlastname;
    string mathlastname;
    string cislastname;
    float credits;
    float totalcredits =0;
    float averagecredits;
    float gpa;
    float totalgpa =0;
    float averagegpa;
    float maxgpa =0;
    float maxcisgpa =0;
    float maxmathgpa =0;
    float tuition;
    float totaltuition =0;
    float averagetuition;
    char doagain = 'y';
    int count;
    
    getdata(major, lastname, credits, gpa, tuition);
    
    totaltuition = compute(totaltuition,tuition);
    averagetuition = compute(totaltuition,count);
    averagegpa = compute(totalgpa,count);
    averagecredits = compute(totalcredits,count);
    
    printdata(averagegpa, totaltuition, averagetuition, averagecredits);
    printdata(newlastname, maxgpa, mathlastname, maxmathgpa, cislastname, maxcisgpa);
    printdata(freshman, sophomore, junior, senior);
    return 0;
}

void getdata(int &major, string &lastname, float &credits, float &gpa, float &tuition, int &senior, int &freshman, int &sophomore, int &junior, float &totaltuition, float &totalcredits, float &totalgpa, float &maxgpa, float &maxmathgpa, float &maxcisgpa, string &lastname, string &newlastname, string &mathlastname, string &cislastname)
{
    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;
    if (credits <= 30)
       freshman++;
    if (credits > 30 && credits <= 60)
       sophomore++;
    if (credits > 60 && credits <= 90)
       junior++;
    if (credits > 90)
       senior++;
    cout << "Enter your gpa: ";
    cin >> gpa;
    cout << "Enter your tuition: ";
    cin >> tuition;
    totalcredits = totalcredits + credits;
    totaltuition = totaltuition + tuition;
    totalgpa = totalgpa + gpa;
    if (maxgpa < gpa)
    {
       newlastname = lastname;
       maxgpa = gpa;
    }
    if (major == 1 && maxmathgpa <gpa)
    {
         mathlastname =lastname;     
         maxmathgpa = gpa;
         }
    if (major == 0 && maxcisgpa <gpa)
     {
        cislastname =lastname;
          maxcisgpa = gpa;
          }
    cout << "Do you want to continue y/n";
    cin >> doagain;
    count++;
    }
    
float compute(float avgtuit, float totaltuit, int cnt)
{
      avgtuit=totaltuit/count;
      return 0;
      }
float compute(float avggp, float totalgp, int cnt)
{
      avggp=totalgp/count;
      return 0;
      }
float compute(float avgcrdts, float totalcrdts, int cnt)
{
      avgcrdts=totalcrdts/count;
      return 0;
      }

void printdata(float avggp, float totaltuit, float avgtuit, float avgcrdts)
{
    cout << "The Total Tuition is: " << totaltuition <<endl;
    cout << "The Average Tuition is: " << averagetuition <<endl;
    cout << "The Average gpa is: " << averagegpa <<endl;
    cout << "The Average number of credits taken is: " <<averagecredits <<endl;
}
void printdata(string newlstnm, float maxgp, string mathlstnm, float mathgp, string cilstnm, float cisgp)
{
    cout << "The student with the highest GPA is: " << newlastname;
    cout << " with " <<maxgpa <<endl;
    cout << "The math student with the highest GPA is: " << mathlastname;
    cout << " with " <<maxmathgpa <<endl;
    cout << "The CIS student with the highest GPA is: " << cislastname;
    cout << " with " <<maxcisgpa <<endl;
}
void printdata(int frshmn, int sphmr, int jnr, int snr)
{
    cout << "The number of freshmen is: " << freshman <<endl;
    cout << "The number of sophomores is: " <<sophomore <<endl;
    cout << "The number of juniors is: " <<junior <<endl;
    cout << "The number of seniors is: " <<senior <<endl;
}

Recommended Answers

All 2 Replies

can You please tel us what error message you are getting ? or can you point out the place where you have said about the error?


Cheers,
saradha

void getdata(int &major, string &lastname, float &credits, float &gpa, float &tuition, int &senior, int &freshman, int &sophomore, int &junior, float &totaltuition, float &totalcredits, float &totalgpa, float &maxgpa, float &maxmathgpa, float &maxcisgpa, string &lastname, string &newlastname, string &mathlastname, string &cislastname);

Use a struct variable to store the student info.
Dont do things like above, it complicates your code a lot.

typedef struct
{

         char fname[20];
         char lname[10];
         /*other student info*/
}student;

void getData(student &st);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.