Hi, guys, I have been working on this short program, it is a simple conversion program from feet/inches to metric system. Everything seems fine, apart from one if statement. There are two, the same if blocks, the only difference is the values in the condition and the sign. Why the first if skips the whole 1-11 inches and then the table prints startign from 5 feet, instead of 4'6"???
Code:
#define FEET_TO_CM 30.48
#define INCH_TO_CM 2.54
float conversion(int, int);
main()
{
int feet, inch;
float converted = 0;
for( feet = 4; feet <= 6; feet++ )
{
for( inch = 0; inch <=11; inch++ )
{
/* that's the two ifs that I am talking about */
if( feet == 4 && inch <= 5 )
break;
if( feet == 6 && inch >= 6 )
break;
converted = conversion(feet, inch);
printf("%2d\'%3d\" %7.2fcm\n",
feet, inch, converted);
}
}
return 0;
}
float conversion( int feet, int inch )
{
return (FEET_TO_CM * feet + INCH_TO_CM * inch);
}
Thanks.