Adding additional steps/loops to a program.

So, I have this program already:

#include <iostream>
using namespace std;
int main( )
{
int Num;
float Input, Sum = 0, Average;
cin >> Num;
for (int i = 1; i <= Num; i++){
cin >> Input;
Sum += Input;
}
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(3);
Average = Sum / Num;
cout << "Average = " << Average << endl;

return 0;
}

It works just fine. Just as it is supposed to. But now, they have thrown me a curve ball and told me to add these two steps (entered below). I have been trying to do step one for about 2 hours now. I cannot figure it out. Thanks for any help in advance!


1. the user is able to enter an arbitrary number of data sets, and you need to average
each data set. Each data set starts with the number of observations, entered as
floating point numbers, and then the observations. When you encounter a data set
that starts with the number 0, you will exit the program. You will need to add an
outer while loop (i.e., a while loop that surrounds your for loop) to your program.
2. the size of the data set must be between 1 and 10 inclusive. You should continually
prompt the user for a valid data size until the user enters either 0, meaning that
you should exit the program, or an integer between 1 and 10. Use a do while to
implement this prompt (you may need to put this prompt in two different places in
your program).
For example, if the input is:
8 1.39 5.5 9.6885 3.198 23.58684 17 -6.58 16.35
1 17.85
3 10 9 4
0
then your output should be
average = 8.767
average = 17.850
average = 7.667
Since each average will print as soon as the dataset for that average has been entered, your
output will not look this nice, because your output will be interspersed with your input.

Thanks again for help!
Same problem discussed here:
http://www.cplusplus.com/forum/beginner/62141/
Topic archived. No new replies allowed.