0

Hi ~ My program seems to work perfectly with the exception of validating user input. I do not want someone to do the work for me, I don't learn anything that way. I need to know why it works not just what or how. I just need a push in the right direction. I was going to post the whole program but thought better of it and am posting just the part not working.

Thanks for any help.

double getRainfallPerMonth(double rain[], int size)
{
	int index = 0;
	
		while(index >= 0)
		{
			for(int index = 0; index <= size - 1; index++)
			{
				cout << "Enter the rainfall for month " << (index+1) << ": ";
				cin >> rain[index];

				if(rain[index] < 0)
				{
					cout << "\nInvalid Entry. Please enter a postive number for monthly rainfall.\n\n";
					cout << "Enter the rainfall for month 1: " << endl;
				}

			}

			
			return index;

		}



	}
2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by scarlettmoon
0

1. you don't need that while loop that starts on line 5 so just delete it2.

2. The for loop sould cout from 0 to < size, not <= size-1. If the value of size is 5, then you want it to count 0, 1, 2, 3 and 4.

3. Use a do loop to verify the value of rainfall >= 0, something like this

do {
   ask question
   input value of rainfall
} while( rainfall < 0);

Edited by Ancient Dragon: n/a

0

1. you don't need that while loop that starts on line 5 so just delete it2.

2. The for loop sould cout from 0 to < size, not <= size-1. If the value of size is 5, then you want it to count 0, 1, 2, 3 and 4.

3. Use a do loop to verify the value of rainfall >= 0, something like this

do {
   ask question
   input value of rainfall
} while( rainfall < 0);

Thanks - it works great now but still adds month one into the accumulated total which is a separate function. I'll try to take it from here.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.