How do I get a variable to recalculate with every iteration of a WHILE loop?

I'm trying to create a counter that increases in increments of two in the first column and then also increases in the second column with the numbers in the first column. The user is supposed to enter the rate at which their hose can put 2 inches of water in a pool (in inches/hour). We are supposed to determine the time (in hours) the user's hose can fill the pool (66 inches total), outputting time in increments of 2 inches until to pool reaches 66" of water. The calculation for time is (inches / fill_rate). I got the left column to increase in increments of 2 all the way up to 66 but the right column is only displaying what the time would be for the first two inches.

For example, if the user-entered fill rate is 2 then it would take one hour to fill 2 inches in the pool. The left column displays 2-66 in increments of two but the right column is just outputting "1" from 2-66. I need the right column to increase with the numbers on the left. So if the number in the left column is 2 then the associated right column number would be 1. If the left column number is 4 then the associated right column number would need to be 2. . . and so on until 66 is reached.

I know that "timeCalc" needs to recalculate in the loop but I don't know how to go about that.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
	// The counter.
	const int min_number = 2;
	const int max_number = 66;
	int num = min_number;	// Counter
	double timeCalc = (num / fill_rate);
	cout << "Your fill rate is 2 inches every " << timeCalc << " hours." << endl;


		cout << "Time Intervals Per 2 Inches Gained" << endl;
		cout << "----------------------------------" << endl;
		while (num <= max_number)
		{
		cout << num << "\t\t" << timeCalc << endl;
		num = num + 2;


		}
Last edited on
timeCalc = 0;
Topic archived. No new replies allowed.