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;

		}



	}

Recommended Answers

All 2 Replies

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);

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.