Temperature

advertisement
Programming Problem #8:
Temperature
Introduction
Two commonly used temperature scales are Celsius (after the Swedish astronomer Anders Celsius
(1701–1744)) and Fahrenheit (named after the Dutch/German/Polish physicist Daniel Gabriel
Fahrenheit (1686–1736)). Today, most countries use Celsius, although Fahrenheit remains the
official temperature scale in the USA, Cayman Islands, Palau, Bahamas and Belize.
Your mission is to develop a temperature conversion program.
Create a program which inputs a temperature value (eg 25) followed by the scale (C or F).
Your program then outputs the temperature using the other scale. See the example below.
Finally, your program should ask whether the user wants to convert another temperature. If so, you
need to loop through again. If not, your program should stop.
Valid temperatures should be between -273C/-460F and 5500C/9900F. Reject any temperatures
outside of these ranges, and any scales which are not C or F.
Comparison of temperature scales
Formulas
F = C * 9 / 5 + 32
C = (F – 32) * 5 / 9
Example input/output
>>>Temperature?
100
>>>Scale? (C/F)
C
>>>212F
>>>Convert another temperature? (Y/N)
Y
>>>Temperature?
98
>>>Scale? (C/F)
F
>>>37C
>>>Convert another temperature? (Y/N)
N
>>>Bye
Activities
1.
2.
3.
4.
5.
Create a defining diagram.
What variables will your program need?
Draw a structure diagram for the program.
Create a set of test data.
Construct the program in Scratch.
Defining Diagram
Inputs
Processing
Outputs
Variables
Variable name
Purpose
Test Data
Input Temp
37C
212F
0C
-40F
Output Temp
98F
100C
32F
-40C
Structure diagram
Scripts
Download