Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include #include #include #include using namespace std; int main() { cout int input, i; //input from user cout cin >> input; int id, marks; ofstream

#include

#include

#include

#include

using namespace std;

int main() {

cout

int input, i; //input from user

cout

cin >> input;

int id, marks;

ofstream outFile;

outFile.open("quizgrades.txt");

if (!outFile.is_open()) {

cout

exit(0);

}

while (input) {

cout

cin >> id;

outFile

for (i = 0; i

do { //validating grade

cout

cin >> marks;

if (marks 100)

cout

else {

outFile

}

} while (marks100);

}

outFile

cin.clear();

cout

cin >> input;

}

outFile.close();

ifstream inFile;

inFile.open("quizgrades.txt");

string line; //to store line from file

int s_count = 0;

//student average, class average, class total variables

double s_avg, classAverage, classTotal;

int total;

classTotal = 0;

while (getline(inFile, line)) {

s_count++;

istringstream iss(line);

iss >> id;

s_avg = 0; total = 0;

for (i = 0; i

iss >> marks;

total = total + marks;

}

//student average+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

s_avg = (double)total / 4;

cout

classTotal = classTotal + s_avg;

}

inFile.close();

classAverage = (double)classTotal / s_count;

printf(" Average quiz score for the class is %.2f ", classAverage);

system("pause");

return 0;

}

So why does my output not read the class averages, or finish the program? It runs fine until the end and then spits out this:

image text in transcribed

store line fromf dent average, clasenter 0 for no students. Enter 1 for more students classTotal; t31\Debug Project31.exe nter the student id 100e Enter quiz grade 86 Enter quiz grade 9e Enter quiz grade 16e Enter quiz grade 70 nter e for no more students to enter. Enter 1 for more students. verage quiz score for the class is-nan (ind) ss any key to continue . count

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions