Question: Experiment 5.3 The following C++ program computes the average of 6 numbers. // Read and compute the average for 6 integers, display the result. #include

Experiment 5.3 The following C++ program computes the average of 6 numbers.

// Read and compute the average for 6 integers, display the result.

#include

using namespace std;

int main( )

{

int x,y,z, p, q, r; // (A)

double average;

// prompt the user:

cout << "Enter six grades separated by spaces, then press :" << endl;

// read and store six integers:

cin >> x >> y >> z >> p >> q >> r; // (B)

average = (x + y + z + p + q + r)/6; // (C)

cout << "The average is " << average << endl;

return 0;

}

Step 1. If we wanted to compute the average of three numbers, we could make some changes in this program. The major changes will make in the lines that are in blue font, also, marked with (A), (B), and (C). Imagine, computing the average of 1000 numbers using the above program and method. That would make things more complicated and the code more tedious. We can simplify this computation using a loop. Following is a new version of the above program written using a while loop.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!