Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

PC Magazine Guide To Client Server Databases

Authors: Joe Salemi

1st Edition

156276070X, 978-1562760700

More Books

Students also viewed these Databases questions