infinite loop issue

The goal of this function is to convert a large number of inches into the format 'miles, yards, feet, and inches'.

But for some reason my code is stuck in an infinite loop in this function. I cannot figure out how to rewrite it so it is not stuck in the loop
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
void Convert(int i, Distance& d)
	{
		d.feet = d.feet + 1; //each time you take away 12, add another to the inches
		
	}
	while ( d.feet > MAX_FT)
	{
		d.yards = d.yards + 1; //took away 3 ft to add to the yardcount
	}

	while (d.yards > MAX_YRDS)
	{
		d.miles = d.miles + 1;
	}

}
Last edited on
It looks like some of the code for your function is missing. Also, what are the inputs for your function?
Oops, i did leave some of it out. This is what i have so far, the input is i

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
void Convert(int i, Distance& d)
{ i;
	while (i > MAX_IN)
	{
		d.feet = d.feet + 1; 
		
	}
	while ( d.feet > MAX_FT)
	{
		d.yards = d.yards + 1; 
	}

	while (d.yards > MAX_YRDS)
	{
		d.miles = d.miles + 1;
	}
}
Last edited on
while (i > MAX_INCHES) i is never changed in your code.
is your function complete? There should have been compiler errors from your mismatched curly braces.
Topic archived. No new replies allowed.