Microsoft Small Basic - A Program to Convert Celsius Temperatures to Fahrenheit
1. Program Objective
Convert Celsius temperature to Fahrenheit and give the user the option to continue converting temperatures or quit.
2. Program Flowchart
Display a welcome message
- While the user wants to convert another temperature:
- Prompt the user to enter a temperature in Celsius
- Convert the Celsius temperature to Fahrenheit
- Display the Fahrenheit temperature
- Ask the user if they want to convert another temperature
Display a thank you message and terminate the program
3. Pseudocode
Display a welcome message
While the user wants to convert another temperature:
Prompt the user to enter a temperature in Celsius
Convert the Celsius temperature to Fahrenheit
Display the Fahrenheit temperature
Ask the user if they want to convert another temperature
Display a thank you message and terminate the program
4. Source Code
' Program Objective: Convert Celsius temperature to Fahrenheit
' and give the user the option to continue converting temperatures or quit.
TextWindow.WriteLine("Welcome to the Celsius to Fahrenheit Converter")
Celsius = 0
Fahrenheit = 0
answer = ""
WHILE answer <> "n"
TextWindow.WriteLine("Enter a temperature in Celsius: ")
Celsius = TextWindow.Read()
Fahrenheit = Celsius * 1.8 + 32
TextWindow.WriteLine("The temperature in Fahrenheit is: " + Fahrenheit)
TextWindow.WriteLine("Do you want to convert another temperature? (y/n)")
answer = TextWindow.Read()
ENDWHILE
TextWindow.WriteLine("Thank you for using the Celsius to Fahrenheit Converter!")
5. Line-by-Line Explanation
TextWindow.WriteLine("Welcome to the Celsius to Fahrenheit Converter")
Displays a welcome message to the user.
Celsius = 0, Fahrenheit = 0, answer = ""
Initializes the variables that will be used to store the Celsius
temperature, Fahrenheit temperature, and user's response.
WHILE answer <> "n"
Starts a loop that will continue as long as the user wants to convert
another temperature.
TextWindow.Write("Enter a temperature in Celsius: ")
Prompts the user to enter a temperature in Celsius.
Celsius = TextWindow.Read()
Reads the user's input and stores it in the Celsius variable.
Fahrenheit = Celsius * 1.8 + 32
Converts the Celsius temperature to Fahrenheit and stores it in the
Fahrenheit variable.
TextWindow.WriteLine("The temperature in Fahrenheit is: " + Fahrenheit)
Displays the Fahrenheit temperature to the user.
TextWindow.Write("Do you want to convert another temperature? (y/n) ")
Asks the user if they want to convert another temperature.
answer = TextWindow.Read()
Reads the user's response and stores it in the answer variable.
ENDWHILE
Ends the loop.
TextWindow.WriteLine("Thank you for using the Celsius to Fahrenheit Converter!")
Displays a thank you message to the user.
6. Console Output from a Program Run
Welcome to the Celsius to Fahrenheit Converter
Enter a temperature in Celsius: 25
The temperature in Fahrenheit is: 77
Do you want to convert another temperature? (y/n) y
Enter a temperature in Celsius: 0
The temperature in Fahrenheit is: 32
Do you want to convert another temperature? (y/n) n
Thank you for using the Celsius to Fahrenheit Converter!
Comments
Post a Comment