Add a while loop to this code: #include \"stdafx.h\" #include <iostream> #includ
ID: 3569422 • Letter: A
Question
Add a while loop to this code:
#include "stdafx.h"
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int test[5];
int sum = 0;
double average;
int index;
cout << fixed << showpoint << setprecision(2);
cout << "Enter five test scores: ";
for (index = 0; index < 5; index++)
{
cin >> test[index];
sum = sum + test[index];
}
cout << endl;
average = sum / 5.0;
cout << "The average test score = " << average << endl;
for (index = 0; index < 5; index++)
if (test[index] < average)
cout << test[index]
<< " is less than the average test score." << endl;
system("PAUSE");
return 0;
}
Explanation / Answer
#include "stdafx.h"
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int test[5];
int sum = 0;
double average;
int index;
cout << fixed << showpoint << setprecision(2);
cout << "Enter five test scores: ";
//for (index = 0; index < 5; index++)
index = 0;
while(index < 5)
{
cin >> test[index];
sum = sum + test[index];
index++;
}
cout << endl;
average = sum / 5.0;
cout << "The average test score = " << average << endl;
//for (index = 0; index < 5; index++)
index = 0;
while(index < 5)
{
if (test[index] < average)
cout << test[index]
<< " is less than the average test score." << endl;
index++;
}
system("PAUSE");
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.