### how to output more than one solution to an expression

This is my program to input student ids and a group of quiz scores and calculate the average for each student as well as the highest and lowest average of all students. I got my program to run successfully, but when I check it against my test data I run into a problem when two or more students have the same average. My question is how to get my output to display more than one student id?

Here is a sample input:
Stud ID: # of Exams: Scores:
1111 3 20 20 20
1112 2 12 14
1113 4 11 19 13 16
1114 3 20 20 20

This is for a 100 lvl intro to C++ class so I would appreciate any "low skill" help=). The commented out if statements with the variables set to ????????? are where I'm stuck. I appreciate any suggestions or tips.

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990`` ``````#include #include #include using namespace std; int main() { ifstream inFile; //open in.data file inFile.open("in.data"); //format output & set decimal precision cout.setf(ios::fixed); cout.precision(2); //declare variables int studId, studCount, count, totalQuizCount, minStud, maxStud; float avg, quizScore, studTot, howManyQuiz, quizTotal, avgOfAllQuizzes; float min = 100.0; float max = 0.0; //begin output cout << "---- Student Quiz Report ----" << endl << endl; cout << setw(20) << left << "Student ID" << setw(10) << "Average of Quizzes" << endl; cout << setw(20) << left << "----------" << setw(10) << "------------------" << endl; //initialize studCount studCount = 0; //input studId & howManyQuiz inFile >> studId >> howManyQuiz; while(inFile) { //increment studCount & begin running sum for totalQuizCount studCount = studCount++; totalQuizCount += howManyQuiz; cout << setw(20) << left << studId; //initialize studTot & count studTot = 0; count = 0; while(count < howManyQuiz) { //input quizScore, begin running sum for quizTotal, & increment count inFile >> quizScore; quizTotal += quizScore; count++; studTot = studTot + quizScore; } //calculate avg & avgOfAllQuizzes avg = studTot/howManyQuiz; avgOfAllQuizzes = quizTotal / totalQuizCount; cout << setw(11) << right << avg << endl; //determine max/min average and maxStud/minStud if(avg > max) { max = avg; maxStud = studId; } // if(avg == max) // { // max = avg; // maxStud = ??????????????; // } if(avg < min) { min = avg; minStud = studId; } // if(avg == min) // { // min = avg; // maxStud = ?????????????; // } //repeat loop inFile >> studId >> howManyQuiz; } cout << endl; cout << "Average of all Quizzes: " << avgOfAllQuizzes << endl << endl; cout << "Student(s): " << maxStud << " had the highest quiz average of: " << max << endl; cout << "Student(s): " << minStud << " had the lowest quiz average of: " << min << endl << endl;; cout << "There were " << studCount << " students and " << totalQuizCount << " quizzes in file." << endl << endl; //close input file inFile.close(); return 0; }``````
You variables were not initialized. For example variable totalQuizCount was not initialized and as the result it has an undefined value after statement

totalQuizCount += howManyQuiz;

You need not to consider condition avg == max because it does not influence on the maximum (or minimum) value of averages.

Last edited on
Topic archived. No new replies allowed.