Home / Expert Answers / Computer Science / an-example-for-while-loop-the-following-mathrm-c-program-computes-the-average-of-6-number-pa734

(Solved): An Example for while loop The following \( \mathrm{C}+ \) program computes the average of 6 number ...



An Example for while loop
The following \( \mathrm{C}+ \) program computes the average of 6 numbers.
// P3_3_1.cpp - Read and

An Example for while loop The following \( \mathrm{C}+ \) program computes the average of 6 numbers. // P3_3_1.cpp - Read and compute the average for 6 integers, display the result. #include using namespace std; int \( \operatorname{man} \) (void) \{ int \( \mathrm{x}, \mathrm{y}, \mathrm{z}, \mathrm{P}, \mathrm{g}, \mathrm{r} ; / / \mathrm{A} \) (A) \( / / \) prompt the user: cout << "Enter six grades separated by spaces, then press : " << endl; \( / / \) read and store six integers: \( c i n>x>y>>>p>p ; \quad / / \) (B) \#include using namespace std; int main(void) int \( \mathrm{x} \); int count \( =0 ; / /(1) \) initialize a counter to 0 to count number of grades double sum \( =0 ; / / \) initialize the sum to 0 to make sure the sum at the beginning is 0 double average; // prompt the user: cout \( << \) "Enter six grades separated by a single space, then press \( < \) Enter \( > \) "; while( count <6) // (2) read six grades and compute their sum, count ensures 6 entries \{ // read each number and compute the sum: \( \operatorname{cin}>>x \); sum \( =s u m+x \) count \( ++, / / \) (3) update the count 3 cout \( << \) endl; average \( =\mathrm{sum} / 6 ; / / \) compute the average, total divided by the number of grades cout \( \ll \) "The average is " \( \ll \) average \( \ll \) endl; \( \quad \) return 0 ;


We have an Answer from Expert

View Expert Answer

Expert Answer


============================= Analysis
We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe