Question: 1. // P2_3_2.cpp - Read and average 6 integers, print the result. #include using namespace std; int main(void) { int x; int count = 0;

1.

// P2_3_2.cpp - Read and average 6 integers, print the result.

#include using namespace std; int main(void) { int 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 : "; while( count < 6) // (2) read six grades and compute their sum, count ensures 6 entries { // read each number and compute the sum: cin >> x; sum = sum + x; count++; // (3) update the count } cout << endl;

average = sum/6; // compute the average, total divided by the number of grades cout << "The average is " << average << endl;

return 0; }

What are the differences between this program and the one given in P2_3_1.cpp? Exercise 2.3.1 Use a text editor to create a file called ex2_3_1.cpp. Copy and paste or carefully copy P2_3_2.cpp program in that file, and then change the program to compute the average of 100 numbers.

2.

// P2_3_3.cpp - Read and average N integers, print the result.

#include using namespace std; int main(void) { int x; int count = 0; // (1) initialize a counter to 0 to count number of values int N; // Number of values for which the average must be computed. 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 number of values, N, to be read in :" << endl; cin >> N;

while( count < N) // (2) read N grades and compute their sum, count ensures N entries { // read each number and compute the sum: cout << " Enter a grade : "; cin >> x; sum = sum + x; count++; // (3) update the count }

if(N == 0) cout << "You haven't enter 0 number, no average will be computed, bye "; else{ average = average = sum/N; cout << "The average of these " << N << " grades is " << average << endl; }

return 0; }

Change program P2_3_3.cpp to work with a do while loop instead of while loop. Call your new program ex2_3_2.cpp, compile and run the program and make sure it produces the correct results.

need 2 of dem plz

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 Databases Questions!