For loop problems

I am trying to make a program that prints all possible combinations of hours (integer values) each of 2 hoses, i and j need to fill a pool. The time it takes to fill the pull with both hoses open is inputed by the user.
For this example I am using 6. The problem is that for some reason, the program skips numbers 10 and 15, which are correct...

Apologies for my terrible english... I couldn't explain it better.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
void menu_pool()
{
	double count = 0;
	double hours;
	double one, two, res;

	cin >> hours;
	double fraction = 1/hours;
	for (double i = hours; i <= (hours * (hours + 1)) ; i++)
	{
		for (double j = hours; j <= (hours * (hours + 1)); j++)
		{	
			one = 1 / i;
			two = 1 / j;
			res = one + two;
			if (res == fraction)
			{
				cout << "A : " << i << endl;
				cout << "B : " << j << endl << endl;
				count++;
			}
		}
	}
	cout << "There are " << count << " possible answers. " << endl;
}

Thanks in advance
Try if ((res-fraction)*(res-fraction)<1.0e-20) instead of if (res == fraction)
Last edited on
Nice thx :D
Topic archived. No new replies allowed.