Based on the question below, write a program using :
a. For loop
b. While loop
c. Do..while loop
A class of ten students took a quiz. The mark is between the ranges 0 - 25 for this quiz is available to you. Determine the average mark for this quiz. Based on this problem, you are required to create a program.
#include <iostream>
#include <string>
using namespace std;
int main()
{
int studentsQuiz[10];
int i=0;
//a. For loop
for(i=0;i<10;i++){
studentsQuiz[i]=-1;
while(studentsQuiz[i]<0 || studentsQuiz[i]>25){
cout<<"Enter the mark between the ranges 0 - 25 for this quiz "<<(i+1)<<": ";
cin>>studentsQuiz[i];
}
}
//b. While loop
//Determine the average mark for this quiz.
i=0;
float sum=0;
float average;
while(i!=10){
sum+=studentsQuiz[i];
i++;
}
average=sum/10.0;
i=0;
cout<<"\nAll marks:\n";
//c. Do..while loop
do{
cout<<"The mark for the student "<<(i+1)<<" is: "<<studentsQuiz[i]<<"\n";
i++;
}while(i!=10);
cout<<"The average mark for this quiz "<<average<<"\n";
system("pause");
return 0;
}
Comments
Leave a comment