When did we assign anything to "cel" in the example?


#1

Im new so bear with me :slight_smile:

Im just curious as to how this little program created any value for “cel” in the temperature conversion example? I get the program but I don’t…

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

cel was never defined. or is cel the return of the function fahrenheitFromCelsius?
And then does that make fahr and cel equal?

maybe I’m getting lost in the function

float fahrenheitFromCelsius(float cel)

Float (means its going to return a float) Fahrenheit (name of function) (float cel) is what? another return?

My mind keep going backwards and forewards., maybe Im just not cut out for this. Even the classical music playing in the background isn’t helping me.

Thanks for all the help!
Josh

printf("%


#2

Just saw the reply below! I posted prematurely and the example below helped a lot!

This forum is great, I just need to look before I type!

Thanks again everyone
Josh


#3

I would be very interested in the response but there are only the posts by JmacUSAF.


#4

Take a look at “Where is cel assigned a value?”

Here is the answer posted there:
"Where is cel assigned a value?

cel is just the name that your fahrenheitFromCelsius() function uses to refer to a number it was handed by the function that called it.

When main() calls your function, it passes in a value of 100 that it knows as “freezeInC”. The fahrenheitFromCelsius() function receives this value, but refers to it by a different name, “cel”.

Specifically, the definition of your fahrenheitFromCelsius(float cel) function specifies “take the first argument to this function and store it in a new local variable called “cel”.”

Does that help?"


#5

hi Rick, etc.

thanks for the explanation, but i thought freezeInC had a value of 0, not 100? that is what the code says in the exercise. where did 100 come from? also, are you saying that the main “defines” the argument of fahrenheitFromCelsius first, and THEN when the function above it uses it, an abbreviation word is used (could be any word, it is arbitrary) to replace freezeInC? if so, why do a replacement, that seems confusing for beginners (since it is not explained).

maybe i am missing something, but i also don’t see why cel was used in the function and how it relates to the main, when the function is called. thanks in advance for any help.


#6

It’s an old thread I know but sometimes the examples are not well explained.