Please I need help for my computer class. I need a program that will prompt the user to enter number of students, then the number of quizzes, then the quiz scores. After that, the program will output the average of the quizzes of each student. So far I have this:
#include <iostream>
#include<cstdlib>
using namespace std;
int main()
{
int quiz = 0;
int score[quiz];
int NumofQuiz = 0;
int a;
double total = 0;
double average;
NumofQuiz = 0;
cout<<"How many scores are there? ";
cin >> quiz;
cout<<"Enter a score: ";
cin >> score[NumofQuiz];
int minimum = score[NumofQuiz]; // initialize to first score.
int maximum = score[NumofQuiz]; // initialize to first score.
while(NumofQuiz < quiz && score[NumofQuiz])
{
total += score[NumofQuiz];
++NumofQuiz;
if(NumofQuiz < quiz)
{
cout<<"Enter a score: ";
cin>>score[NumofQuiz];
if (score[NumofQuiz] < minimum)
{
minimum = score[NumofQuiz];
}
if (score[NumofQuiz] > maximum)
{
maximum = score[NumofQuiz];
}
}
}
cout<< "The entered test scores are: ";
for (a = 0; a < NumofQuiz; ++a)
cout<<score[a]<<" ";
average = total / NumofQuiz;
cout<<endl<<"The average test score is "<<average<<endl;
system ("PAUSE");
}
The only thing I need is to prompt the user to enter the number of students and that the program will do repeat this as many times as the number of students.
#include <iostream>
#include<cstdlib>
usingnamespace std;
int main()
{
int quiz = 0;
int score[quiz];
int NumofQuiz = 0;
int a;
double total = 0;
double average;
NumofQuiz = 0;
cout<<"How many scores are there? ";
cin >> quiz;
//Do while loop based on quizz. possibly do{.......quizz--}while(quiz!=0)?
cout<<"Enter a score: ";
cin >> score[NumofQuiz];
int minimum = score[NumofQuiz]; // initialize to first score.
int maximum = score[NumofQuiz]; // initialize to first score.
while(NumofQuiz < quiz && score[NumofQuiz])
{
total += score[NumofQuiz];
++NumofQuiz;
if(NumofQuiz < quiz)
{
cout<<"Enter a score: ";
cin>>score[NumofQuiz];
if (score[NumofQuiz] < minimum)
{
minimum = score[NumofQuiz];
}
if (score[NumofQuiz] > maximum)
{
maximum = score[NumofQuiz];
}
}
}
cout<< "The entered test scores are: ";
for (a = 0; a < NumofQuiz; ++a)
cout<<score[a]<<" ";
average = total / NumofQuiz;
cout<<endl<<"The average test score is "<<average<<endl;
system ("PAUSE");
}
Try looking up control statements. A while loop with a decrement based on number of students would most likely do what you're trying to accomplish.