Problem

(Debug) By mistake, a programmer puts the statement average = total / count; in the while...

(Debug) By mistake, a programmer puts the statement average = total / count; in the while loop immediately after the statement total = total + num; in Program. As a result, the while loop becomes the following:

while (count <= MAXNUMS){cout << "Enter a number: ";cin >> num;total = total + num;average = total / count;count++;}

a. Will the program yield the correct result with this while loop?


b. From a programming perspective, which while loop is better to use and why?

#include #include using namespace std;int main( ){const int MAXNUMS = 4;int count;double num, total, average;cout << "\nThis program will ask you to enter "<< MAXNUMS << " numbers.\n";count = 1;total = 0;while (count <= MAXNUMS){cout << "Enter a number: ";cin >> num;total = total + num;count++;}count--;average = total / count;cout << "\nThe average of the numbers is " << average << endl;return 0;}

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 5.2
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT