Help with simple program?

I'm reviewing the chapters for my C++ class and came across this problem:

Develop a program to find the average of a sequence of integers entered by the user.
The program will continue to prompt the user for numbers until -999 is entered. (The -999 is an "end of data" flag, and is not considered part of the data. It should not be included in your calculations.)
After -999 is entered to indicate that all of the values have been entered,
display the sum, count, the smallest number entered, the largest number entered,
and the average of all the numbers entered.

I'm looking for an alternative way to do this.
can anyone show me how to do this with a simple "while" loop?
if there is another way that is easier to understand or something, that would help too.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
std::vector<int> arr;
do
{
    int num;
    std::cin >> num;
    if(std::cin)
    {
        arr.push_back(num);
    }
    else
    {
        std::cin.clear();
    }
}while(num != -999);
arr.pop_back();
Here is the input. Now the logic for finding the Sum, total Size, Minimum, Maximum, and Mean of all the numbers is up to you:
Last edited on
Topic archived. No new replies allowed.