I'm scratching my head over this one. My input for feet is always recorded as 0 when I print within the calc() function, but it is correct when printed in the main() function. What's going on?
Code:
#include <stdio.h>
float input (void)
{
float x;
scanf("%f", &x);
getchar();
return x;
}
float calc ()
{
float y, feet, inches;
y = 30.48 * feet + 30.48 * (inches / 12);
printf("%f and %f", feet, inches);
printf("%f", y);
return y;
}
void output ()
{
int meters;
float centimeters;
printf("\nThe value is equivalent to %d meters and %.2f centimeters.", meters, centimeters);
}
int main (void)
{
int meters;
float feet, inches, metric, centimeters;
char ans;
printf("This program converts a length in feet and inches into meters and centimeters.\n");
do
{
printf("Insert length in feet: ");
feet = input ();
printf("Insert length in inches: ");
inches = input ();
metric = calc (feet, inches);
meters = metric / 100;
centimeters = (metric - meters) * 100;
output (meters, centimeters);
printf("\nWould you like to try again? [Y/N]");
scanf("%c", &ans);
getchar();
} while (ans == 'y' || ans == 'Y');
return 0;
}