Average of n numbers

So basically I have to average how many ever numbers a user enters. I can only accept positive numbers so if a negative number is entered, I have to tell them to enter another positive number instead. I have the code working except it also averages negative numbers because I'm not quite sure how to add an if statement that re-asks the user to input a different number when a negative one is entered.

Any help is appreciated
Last edited on
1
2
3
4
while (x <0)
{
ask user to input a new number;
}
Something like this :
1
2
3
4
5
6
cin >> input;
if(input < 0)
{
    cout << "No!!! A negative number is entered!!! Please try again\n\n";
    i--; continue;
}
Thank you both for the help. I now have it working.
Topic archived. No new replies allowed.