I'm very new to programming and ive been trying to figure out this problem for a few days and still have no luck, I cant figure out how to get the average to ignore an out of range number. Also the range is the max- the min which i cant get to work either please help.

Code:
#include <iostream>
using namespace std;

int main()
{
double x;
double sum = 0.0;
int number = 0;
double average;
double max = 0;
double min = 0;

while (cin>>x)

{
if ((x < 0) || (x > 100))
{
cin.ignore(3,'\n');

cout << "Out of range ; ignored." << endl;
}

if (x > max)
max = x;

if (min > x)
x = min;

sum += x;
number++;
}
if (number > 0)
{
average = sum / number;
cout<<"The average is "<< average;
cout<<" The range is "<< max - min;
cout << endl;
}
return 0;
}

Last edited by shabbir; 17Oct2008 at 08:49.. Reason: Code block