4.10: Condition Examples
- Page ID
- 10646
\( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)
Temperature
Pseudocode
Function Main Declare String choice Assign choice = GetChoice() If Choice = "C" Or Choice = "c" Call ProcessCelsius() False: If Choice = "F" Or Choice = "f" Call ProcessFahrenheit() False: Output "You must enter C to convert to Celsius or F to convert to Fahrenheit!" End End End Function CalculateCelsius (Real fahrenheit) Declare Real celsius Assign celsius = (fahrenheit - 32) * 5 / 9 Return Real celsius Function CalculateFahrenheit (Real celsius) Declare Real fahrenheit Assign fahrenheit = celsius * 9 / 5 + 32 Return Real fahrenheit Function DisplayResult (Real temperature, String fromScale, Real result, String toScale) Output temperature & "° " & fromScale & " is " & result & "° " & toScale End Function GetChoice Declare String choice Output "Enter F to convert to Fahrenheit or C to convert to Celsius:" Input Choice Return String choice Function GetTemperature (String scale) Declare Real temperature Output "Enter " & scale & " temperature:" Input temperature Return Real temperature Function ProcessCelsius Declare Real temperature Declare Real result Assign temperature = GetTemperature("Celsius") Assign result = CalculateCelsius(temperature) Call DisplayResult(temperature, "Fahrenheit", result, "Celsius") End Function ProcessFahrenheit Declare Real temperature Declare Real result Assign temperature = GetTemperature("Fahrenheit") Assign result = CalculateFahrenheit(temperature) Call DisplayResult(temperature, "Celsius", result, "Fahrenheit") End
Output
Enter C to convert to Celsius or F to convert to Fahrenheit: c Enter Fahrenheit temperature: 100 100° Fahrenheit is 37.7777777777778° Celsius Enter C to convert to Celsius or F to convert to Fahrenheit: f Enter Celsius temperature: 100 100° Celsius is 212° Fahrenheit Enter C to convert to Celsius or F to convert to Fahrenheit: x You must enter C to convert to Celsius or F to convert to Fahrenheit.
Flowchart