Lesson goal: Using functions to convert temperatures

Previous: Returning values | Home | Next: Finding the Greatest Common Divisor (GCD)

Quick question: you are in London, England and it's $32^\circ$C outside. Is it hot or cold?

In the last lesson you learned how to return a value to a calling statement from within a function. Let's use such functions to convert between the Fahrenheit and Celsius temperature scales.

We'll use the standard formulas to convert between these two scales, which are $F=\frac{9}{5}C+32$ and $C=\frac{5}{9}(F-32)$.

Now you try. Program in the correct conversion formula into the parenthesis of the return statement.

Type your code here:


See your results here:

This program won't run. You have to fill in something into the return( ) statement's parenthesis. Think carefully now...the function cel2far (short for "Celsius to Fahrenheit") has a parameter called cel coming into it. Use the variable cel in the proper conversion formula to return the equivalent temperature in $^\circ F$ back to the print statement in the main program. Dismiss.
Show a friend, family member, or teacher what you've done!

Here is a share link to your code:

Does your code work? Want to run it on your iPhone?

Here's your code:

  1. Use [Control]-[C] (Windows) or [⌘]-[C] (MacOS) to copy your code.

  2. Paste it using [Control]-[V] (Windows) or [⌘]-[V] (MacOS) into this page

  3. Then click the "Use on iPhone" button that you'll see.