error: incompatible types for a function that returns float in C

If C compiler does not know the function signature, it deduces input parameters based on arguments supplied, and deduces return type to be int.

Either declare the function before you use it for the first time:

float calculate_fare(int stops);

or put entire definition at the top of your translation unit.

That is, the error:

[...] previous implicit declaration for 'calculate_fare' was here [...]
//             ^^^^^^^^ ^^^^^^^^^^^

states that the compiler had no previous declaration for the function, and had to generate one on its own.

Browse More Popular Posts

Leave a Comment