Converting inches to feet 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",&amp;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 &lt;stdio.h&gt;
int main()
{
    float distance, floatFeet, input;
    int feet;

    printf("Enter a distance in inches (0 to quit): ");
    scanf("%f", &amp;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", &amp;input);
    }
}
You could move the duplicated lines into a function, something like this should work:

#include &lt;stdio.h&gt;

float get_input(void)
{
    float input;

    printf("Enter a distance in inches (0 to quit): ");
    scanf("%f", &amp;input);

    return input;
}

int main()
{
    float inches, floatFeet, input;
    int feet;

    while (input = get_input())
    {
        feet = input/12;
        inches = (input-feet*12);
        floatFeet = input/12;
        printf("%d feet and %f inches or %f feet \n\n",feet,inches,floatFeet);
    }

    printf("Goodbye!\n");
}