Question: P2_4_1.cpp - Read and average some integers, print the result. // This program continue asking for a new number until the user enters a 0
P2_4_1.cpp - Read and average some integers, print the result. // This program continue asking for a new number until the user enters a 0 to terminate the program #include
while( choice == 1) // (2) read N grades and compute their sum, count ensures N entries { // read each number and compute the sum: cout << " Enter a grade
if(count == 0) cout << "You haven't entered any number, no average will be computed, bye "; else{ average = sum/count; //Notice that we have divided by count this time cout << "The average of these " << count << " grades is " << average << endl; }
return 0; }
Exercise 2.4.1 In program P2_4_1.cpp, right at the beginning you have initialized the choice to 1. You did that to get the while loop to run at least once. If you use a do ... while instead, you wouldn't need to initialize the choice. Re-write the above program, call the new program ex2_4_1.cpp, so that is uses do ... while. Do not initialize the choice to 1 this time and compile and run the program. Does the program work the same way?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
