The following loop is supposed to read some numbers until


1. The following loop is supposed to read some numbers until it reaches a sentinel (in this case -1). It is supposed to add all of the numbers except for the sentinel. If the data looks like:

12 5 30 48 -1

the program fails to do what it is purported to do. Correct it.

#include

using namespace std;
int main()
{
int total = 0,
count = 0,
number;

do
{
cin >> number;
total = total + number;
count++;
}
while (number != -1);

cout << "The number of data read is " << count << endl;
cout << "The sum of the numbers entered is " << total
<< endl;

return 0;
}

 

Solution Preview :

Prepared by a verified Expert
Basic Computer Science: The following loop is supposed to read some numbers until
Reference No:- TGS01262242

Now Priced at $20 (50% Discount)

Recommended (90%)

Rated (4.3/5)