Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Help on C++ array coding! So this program is suppose to take in names (up to 20)

ID: 3749894 • Letter: H

Question

Help on C++ array coding! So this program is suppose to take in names (up to 20) and quiz scores (up to 10). After typing the name of a student it asks to enter the number of scores based on how many quizzes there were (ex. 5 quiz score input if 5 quizzes were taken) after that it displays a table that list the student name and then their average score (one name and one score per line). Then at the bottom it's suppose to display the highest average and the lowest average.

So far I have the following: I figured it out until it asks for average of each user and the max/min value. What do I need to do from here? I tried solving for max/min but I am doing something wrong. Thank you

The bottom image is what it suppose to look like. Its not my program.

#include

#include

#include

using namespace std;

int main() {

const int Max_Students = 20;

const int Max_Quizzes = 10;

double Students[Max_Students], Quizzes[Max_Quizzes];

int numStudents = 0, numQuizzes = 0;

string StudentName;

double score = 0, sum = 0, average = 0;

double max = -200, min = 200;

cout << "Enter the number of students (1-20): ";

cin >> numStudents;

cout << "Enter the number of quizzes (1-10): ";

cin >> numQuizzes;

do {

for (int j = 0; j < numStudents; j++) {

cout << " What is the name of the student? ";

cin >> StudentName;

cin.ignore();

getline(cin, StudentName);

for (int i = 1; i <= numQuizzes; i++) {

cout << "Enter score " << i << ": ";

cin >> score;

sum += score;

}

for (int i = 1; i < numQuizzes; i++) {

if (score > max) {

max = score;

}

}

for (int i = 1; i < numQuizzes; i++) {

if (score < min) {

min = score;

}

}

}

average = sum / numQuizzes;

cout << max << " and " << min;

} while (numStudents < 0 || numStudents > 20);

system("pause");

return 0;

}

11-20); 3 Entte nmber of studlent 1- Enter number of quizzes (1-10): 2 Enter student nameRick Flair EnteF sCOre 1: Enter score 2: Enter student name: Arn Anderson Enter SCore 1: Enterscore 2: 89 93 Enter student name : steve Aust in 81 86 71.5 91.0 83.5 91.0 71.5 score 1: Enter score 2: Rick Flair Arn Anderson Steve Austin Highest Auerage: OwesSt HUeage- Press any key to continue . . .

Explanation / Answer

Hi , following is the exact code for your requirement.
Kindly follow through the comments in the code for what works how. If any doubts write in comments, I will surely follow up.

==========================================================================

#include <iostream>

#include <string>

using namespace std;

int main(){

const int Max_Students = 20;

const int Max_Quizzes = 10;

int numStudents=0, numQuizzes=0, i=0,j=0; //Taken two variables i and j to use in for loops iteration

double sum=0,score=0,avg_score=0,max_score=0,min_score=0;

string student_names[Max_Students]; //This array stores the names of the students

double student_avg_score[Max_Students]; //This array stores the average scores of the students. Note here the indexes in both arrays correspond to the same student

cout << "Enter the number of students (1-20): ";

cin >> numStudents;

cout << "Enter the number of quizzes (1-10): ";

cin >> numQuizzes;

//following if statement checks if the user has entered number of students and quizzes as per the given conditions (0-20) and (0-10)

if( (numStudents>0 && numStudents <21) && (numQuizzes >0 && numQuizzes < 11) ){

for( i=0; i<numStudents; i++){

cout<<" Enter student name: ";

cin.ignore();

getline(cin, student_names[i]);

sum = 0; //Initialize sum and avg_score to zero before use

avg_score = 0;

for(j=0; j<numQuizzes; j++){

cout<<" Enter score "<<j+1<<": ";

cin>>score;

sum+=score;

}

avg_score = sum/numQuizzes; //average calculation

student_avg_score[i] = avg_score; //average array gets populated here

}

for(i=0; i<numStudents; i++){

cout<<" "<<student_names[i]<<" "<<student_avg_score[i];

}

//the following code block calculates the minimum and maximum score of the students

max_score = student_avg_score[0];

min_score = student_avg_score[0];

for (i = 0; i < numStudents; i++)

{

if (student_avg_score[i] > max_score)

{

max_score = student_avg_score[i];

}

else if (student_avg_score[i] < min_score )

{

min_score = student_avg_score[i];

}

}

cout<<" Highest Average: "<<max_score; //print highest and lowest avg

cout<<" Lowest Average: "<<min_score;

}

else

cout<<" Please check the number of students and quizzes as per the limit ";

return 0;

}