- 2
How to compute the average of 4 quizzes using while statement
While statement
6 odpowiedzi
+ 3
Define *quizzes*
+ 3
quizzes?
what is quizzes?
+ 2
What is the full task?
Just tell me
+ 1
the average
+ 1
You mean 4 numbers?
+ 1
Have you solved this? well, in case you haven't, here's an example, go through it, I put comments some places to explain.
#include <iostream>
using namespace std;
int main()
{
// Sample quiz scores
float quiz[] = {7.54, 8.35, 7.92, 6.98};
int index = 0; // For array iteration
float sum = 0; // Score summary
while(index < 4)
{
sum += quiz[index]; // Sum up scores
index++;
}
// divide by number of quizzes
float avg = sum / 4;
cout << "Your quiz average " << avg;
return 0;
}
Hth, cmiiw