I have a very simple program that simply asks for ones weight and converts it to the value of platinum. I am new to C so the mistake could be anywhere. But when I use scanf, it asks for input at the very beginning rather than following the sequence of code:
code:
#include <stdio.h>
int main(void)
{
float weight;
float value;
printf("Are you worth your weight in platinum?\n");
printf("Let's check it out.\n");
printf("Please enter your weight in pounds: ");
scanf("%f", &weight);
printf("%.2f\n", weight);
value = 1700.0 * weight * 14.5833;
printf("Your weight in platinum is worth $%.2f.\n", value);
printf("You are easily worth that! If platinum prices drop,\n");
printf("eat more to maintain your value.\n");
return 0;
}
Output:
123
Are you worth your weight in platinum?
Let's check it out.
Please enter your weight in pounds: 123.00
Your weight in platinum is worth $3049368.00.
You are easily worth that! If platinum prices drop,
eat more to maintain your value.
If you notice in the output the user has to enter input before the first line prints. Why is this?