EvilZone
Programming and Scripting => C - C++ => Topic started by: Polyphony on October 02, 2012, 01:47:47 AM
-
#include <stdio.h>
int main()
{
float f, answer;
answer= 5.0 / 9.0 * (f-32.0);
printf("fahrenheit =");
scanf("%f", f);
printf("\n");
printf("%.1f to celsius is %.1f\n", f, answer);
return 0;
}
is it because I'm using scanf() wrong? the compiler (GCC) gives me 2 warnings...
fahrenheit_to_celsius.c:7:2: warning: format ‘%f’ expects argument of type ‘float *’, but argument 2 has type ‘double’ [-Wformat]
fahrenheit_to_celsius.c:5:24: warning: ‘f’ is used uninitialized in this function [-Wuninitialized]
I don't really get the 1st error as I know at the top i initialized the variables as floats.
-
-- scanf("%f", f);
++ scanf("%f", &f);
And you are performing your operations before getting the input from the user. Should be
#include <stdio.h>
int main()
{
float f, answer;
printf("fahrenheit =");
scanf("%f", f);
answer= 5.0 / 9.0 * (f-32.0);
printf("\n");
printf("%.1f to celsius is %.1f\n", f, answer);
return 0;
}
-
gotcha, simple noob mistake : / I guess I wasn't thinking clearly when I was programming this ;) thanks for the solution