# fahrenheitFromCelcius function question

#1

Here’s the output when I do the fahrenheitFromCelcius function.

50.000000 Celcius is 122.000000 Fahrenheit
0.000000 Celcius is 32.000000 Fahrenheit
water freezes at 32.000000 degrees Fahrenheit

I wonder where the 2nd line (0.000000 Celcius is 32.000000 Fahrenheit) is coming from since there’s only 2 printf statements. I would appreciate your help, been trying to figure this out for 2 days already

here’s the’s code.

[code]#include <stdio.h>

float fahrenheitFromCelcius (float cel)

{

``````float fahr = cel * 1.8 + 32.0;
printf("%f Celcius is %f Fahrenheit\n", cel, fahr);
return fahr;
``````

}

int main(int argc, const char * argv[])
{

``````fahrenheitFromCelcius(50	);
float freezeInc = 0;
float freezeInF = fahrenheitFromCelcius(freezeInc);
printf("water freezes at %f degrees Fahrenheit\n", freezeInF);
return 0;
``````

}
[/code]

#2

It is due to these two lines of code in main:

`````` float freezeInc = 0;
float freezeInF = fahrenheitFromCelcius (freezeInc);``````

and the printf statement in the function:

``````float fahrenheitFromCelcius (float cel)
{
float fahr = cel * 1.8 + 32.0;
printf ("%f Celcius is %f Fahrenheit\n", cel, fahr);
return fahr;
}``````

It is better to write the above function without the printf like this:

``````float fahrenheitFromCelcius (float cel)
{
return cel * 1.8 + 32.0;
}``````

#3

Thank you very much! Finally! You’re great sir!