This was a homework assignment that I'm now done with - I submitted it as is. However the fact that I needed to use the same code twice bugged me... The double code is:
printf("Enter a distance in inches (0 to quit): ");
scanf("%f",&input);
Is there a better way to do the same thing in my loop instead of the double scanf
/printf
? It does need to quit the program immediately if a 0 is entered.
#include <stdio.h>
int main()
{
float distance, floatFeet, input;
int feet;
printf("Enter a distance in inches (0 to quit): ");
scanf("%f", &input);
while (input != 0)
{
feet = input/12;
distance = (input-feet*12);
floatFeet = input/12;
printf("%d feet and %f inches or %f feet \n\n", feet, distance, floatFeet);
printf("Enter a distance in inches (0 to quit): ");
scanf("%f", &input);
}
}