Error checking an array

I'm writing a program which calculates the average rainfall for 12 months. I need to make sure no chars or negative numbers are inputted into my array but I'm not quite sure how to do that.

This is what i have so far. Any suggestions would be appreciated.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
void getRainfall(double rainfall[]) //parameter list
{
	for (int i = 0; i < 12; i++)
	{
		cout << "Enter rainfall: ";
		cin >> rainfall[i];

		if (rainfall[i] <= 0)
		{
			

		}


	}
}


Thanks in advance!
to loop until user inputs the right value write
1
2
3
do cin >> rainfall[i];
while(rainfall[i] < 0 || //loop if value is lower than 0
    cin.rdstate() & failbit);//loop if non-integer value was entered 

I'm not sure it's the right way to check if int was inputed...
it didnt work, i dont quite know what you mean by failbit.
Topic archived. No new replies allowed.