When I try to compile this:
Code:
/* Exercise 1.15. Rewrite the temperature conversion program of Section 1.2 to use a function for conversion. */
/* C = (5 / 9)(F - 32) */
#include <stdio.h>
main()
{
int fahr;
printf("\n\nfahrenheit\tcelsius\n");
for(fahr = 0; fahr <= 300; fahr = fahr + 20)
printf("%3d\t\t%3.0f\n",fahr,fahr_cel(fahr));
printf("\n\n");
return 0;
}
float fahr_cel(int fahr)
{
float cels;
cels = (5.0 / 9.0) * (fahr - 32.0);
return cels;
}
I get this from the compiler:
Code:
exercise 1-15.c: In function ‘main’:
exercise 1-15.c:13: warning: format ‘%3.0f’ expects type ‘double’, but argument 3 has type ‘int’
exercise 1-15.c: At top level:
exercise 1-15.c:20: error: conflicting types for ‘fahr_cel’
exercise 1-15.c:13: error: previous implicit declaration of ‘fahr_cel’ was here
But I can't find what's wrong with the code. Why does the argument 3 has type int instead of float??