Question: Requirements: 1. Use a nested loop structure to input the data and Write the data to a text file. a. The outer loop will be

Requirements: 1. Use a nested loop structure to input the data and Write the data to a text file. a. The outer loop will be a while loop; the inner loop will be a for loop (4 quizzes). b. Validate whether the quiz scores are in range (0100). c. Since you do not know how many students will be entered, add a way to quit the loop. d. Add spaces in between each item added to the text file. Add a new line after each student. The text file that your program creates will look like the following 2. Use a nested loop structure to read the data from the text file and calculate the students average grade. a. The outer look will be a while loop; the inner loop will be a for loop (4 quizzes) b. To calculate each students average score, use a total variable initialized to 0 before the for loop, then calculate the students average after the loop. c. To calculate the class average, initialize a classTotal variable to 0 before the while loop, add each students total into the classTotal following the for loop, then calculate the classAverage after the while loop. d. Only display 2 decimals for the averages.

My code so far:

#include

#include

#include

using namespace std;

int main()

{

ifstream inFile;

ofstream outFile;

int studentId, quiz1=0, quiz2=0, quiz3=0, quiz4=0, choice;

int quizGradeaverage = 0;

for (int x = 0; x < 4; x++) {

cout << "Enter student ID: ";

cin >> studentId;

cout << "Enter quiz grade 1: ";

cin >> quiz1;

cout << "Enter quiz grade 2: ";

cin >> quiz2;

cout << "Enter quiz grade 3: ";

cin >> quiz3;

cout << "Enter quiz grade 4: ";

cin >> quiz4;

cout << endl;

cout << "Enter 0 for no more students. Enter 1 for more students." << endl;

cin >> choice;

if (choice == 0)

break;

if (choice == 1)

continue;

}

quizGradeaverage += quiz1 + quiz2 + quiz3 + quiz4 / 1200;

cout << "The average of the student's test scores is: " << quizGradeaverage << endl;

system("pause");

return 0;

}

I can't figure out what the while loop is supposed to be or how to calculate the average correctly. Any help would be greatly appreciated!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!