How can I answer the following questions for this program?

The questions are:
i.What do we call a number like 0 in this problem? and the variables x? y? and
num? (They all have loop related names, so the answer isn’t int).
ii. What is the output if the user enters the following?
10 12 15 18 0[ENTER]
n[ENTER]
iii. What is the output if the user enters the following?
10 12 15 18 0 4 7[ENTER]
n[ENTER]
How is this related to the answer in (i)? Why?
iv. What is the output if the user enters the following?
10 12 15 18 0[ENTER]
y[ENTER]
10 12 0[ENTER]
n[ENTER]
Is this what is expected?How do you fix it?
v. What is the output if the user enters the following?
0 5 10 12[ENTER]
n[ENTER]
Why does this happen? How can you fix it so a warning is printed out
instead?

The code:
#include <iostream>
#include <iomanip>
#include <cctype>

using namespace std;
int main()
{
int x = 0, num;
double y = 0;
char more;

do
{
cout << "Enter a series of numbers separated by spaces and terminated by zero:\n";
cin >> num;
while (num != 0)
{
x++;
y += num;
cin >> num;
}

double avg = y/x;
cout << fixed << setprecision(2) << "\nAverage: " << avg;

cout << "\n\nDo you have another list of numbers (y/n)? ";
cin.sync(); // Ignores any characters left in the input
cin >> more;

cout << endl << endl;

} while (tolower(more) == 'y');

return 0;
}
Topic archived. No new replies allowed.