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
// 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started