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

/Program to find the average test score and output the average //test score and

ID: 3687568 • Letter: #

Question

/Program to find the average test score and output the average//test score and all the test scores that are less than //the average test score. #include #include using namespace std; int main() { int test0, test1, test2, test3, test4; double average; cout << fixed << showpoint << setprecision(2); cout << "Enter five test scores: "; cin >> test0 >> test1 >> test2 >> test3 >> test4; cout << endl; average = (test0 + test1 + test2 + test3 + test4) / 5.0; cout << "The average test score = " << average << endl; if (test0 < average) cout << test0 << " is less that the average test score." << endl; if (test1 < average) cout << test1 << " is less that the average test score." << endl; if (test2 < average) cout << test2 << " is less that the average test score." << endl; if (test3 < average) cout << test3 << " is less that the average test score." << endl; if (test4 < average) cout << test4 << " is less that the average test score." << endl; return 0; } Modify the above program such that it uses one array variable instead of the five variables.

Explanation / Answer

SOlution:

#include <iostream>
#include <conio.h>
#include <iomanip>

using namespace std;

int main() {
   int arr[5];
   double average;
   cout << fixed << showpoint << setprecision(2);
   cout << "Enter five test scores: ";
   cin >> arr[0] >> arr[1] >> arr[2] >> arr[3] >> arr[4];
   cout << endl;
   average = (arr[0] + arr[1] + arr[2] + arr[3] + arr[4]) / 5.0;
   cout << "The average test score = " << average << endl;
   if (arr[0] < average)
       cout << arr[0] << " is less that the average test score." << endl;
   if (arr[1] < average)
       cout << arr[1] << " is less that the average test score." << endl;
   if (arr[2] < average)
       cout << arr[2] << " is less that the average test score." << endl;
   if (arr[3] < average)
       cout << arr[3] << " is less that the average test score." << endl;
   if (arr[4] < average)
       cout << arr[4] << " is less that the average test score." << endl;
   return 0;
}

Sample run :

Enter five test scores: 20 30 40 50 70

The average test score = 42.00
20 is less that the average test score.
30 is less that the average test score.
40 is less that the average test score.