CSE 110 | Programming Building Blocks

04 Prepare: Checkpoint

Unit Conversion

Overview

Practice solving problems with variables and expressions, and displaying the results.

The Problem: Converting between different types of units

Temperature, like many other values, can be measured in different kinds of units. In this case, you might measure the value of degrees in Fahrenheit, Celsius, or Kelvin. Converting from one scale to another uses the same calculation over and over again for different input values.

Situations like this one are the perfect case for a program that can be coded to complete the steps of the calculation.

Assignment

Write a program to convert from Fahrenheit to Celsius. Display the result to one decimal place of precision.

To convert degrees in Fahrenheit to Celsius you need to subtract 32 from the Fahrenheit amount and then multiply it by the fraction 5/9.

Here is an example of the program when it runs:


What is the temperature in Fahrenheit? 81
The temperature in Celsius is 27.2 degrees.

Another example is:


What is the temperature in Fahrenheit? 12
The temperature in Celsius is -11.1 degrees.

Sample Solution

When your program is finished, please view a sample solution of this program to compare your approach to that one.

You should work to complete this checkpoint program first, without looking at the sample solution. However, if you have worked on it for at least an hour and are still having problems, you may feel free to use the sample solution to help you finish your program.

Testing Procedure

Verify that your program works correctly by following each step in this testing procedure:

  1. Try the values in the examples on this page and ensure that your program generates the same results.

  2. Verify that you are displaying the result to 1 decimal point of precision as shown.

  3. Try converting 32 degrees Fahrenheit (freezing, which should be 0 degrees Celsius) and 212 degrees (boiling, which should be 100 degrees Celsius)

  4. Try converting 0 and a negative number and make sure they come out as you would expect.

  5. Verify that you have used good style, by checking the variable names you have used as well as the use of blank lines and whitespace around your operators.

Submission

When complete, please report your progress in the associated I-Learn quiz.