This program kinda works, but I have one problem. I setup this program to display a message when someone enters a negative number, but I how do I set the count back to zero. Even though mesage prompts the user that a negative number is invalid, it still calculates the number in the average. Please help

#include <iostream>
using namespace std;

int main()
{
// Variables
const int positive_numbers = 10;
int numbers[positive_numbers];
double average;
double sum = 0.0;
int num;
//Read all numbers
for (int i = 0; i < positive_numbers; i++)
{
cout << "Enter a number: ";
cin >> num;
if( num < 0 ) cout << "Invalid! Please enter a number greater than or equal to zero." << endl;
numbers[i] = num;
sum += numbers[i];[/B]
}

//Find the average
average = sum/10;

// Display average
cout <<"\nThe average is " << average <<"\n\n";


return 0;
}

it now does not stop after ten numbers. The program let the user enter 10 number and outputs the average. It now seems like you can enter an infinite amount of numbers. when a user enter a negative number, I need the program to not calculate that number as part of the ten. any other suggestions.

This article has been dead for over six months. Start a new discussion instead.