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

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;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote