Question: Lab 3 - Calculations Instructions: Complete each problem. If you're struggling with a problem, feel free to ask questions on the class forum. This lab

Lab 3- Calculations
Instructions: Complete each problem. If you're struggling with a problem, feel free to ask questions on the class forum.
This lab is optional, but it gives you valuable programming experience. You should definitely complete the lab if you can.
Problem 1- Basic Calculations
Write a Console application to convert a temperature from Fahrenheit to Celsius and back again (to verify the math!).
Hint: What data type should you use to store the degrees? Your answer may have a dramatic affect on the outcome of your calculations ...
You need to use three variables for this program: one variable for the original temperature in Fahrenheit, one variable for the calculated temperature in Celsius, and one variable for the calculated temperature in Fahrenheit (when you convert from Celsius back to Fahrenheit). Be sure to name your variables appropriately.
To get the original temperature in Fahrenheit from the User:
Assuming you declared your first variable as a float named originalFahrenheit, here's the code you'd use to get the original temperature from the user:
Console.Write("Enter temperature (Fahrenheit): ");
originalFahrenheit = float.Parse(Console.ReadLine());
The console ReadLine method returns whatever string the user typed on the keyboard before pressing the Enter key. Passing that string as an argument to the float Parse method converts the string to a float.
To go from Fahrenheit to Celsius:
- Begin by subtracting 32 from the Fahrenheit number.
- Divide the answer by 9.
- Then multiply that answer by 5.
For example, if it's 70 degrees F outside, and you want to know the temperature in C :
-\(70-32=38\)
-\(38/9=4.2\)
-4.2*\(5=21.1\)
To go from Celsius to Fahrenheit:
- Begin by multiplying the Celsius temperature by 9.
- Divide the answer by 5.
- Now add 32.
Display the following message:
XX degrees Fahrenheit is YY degrees Celsius
YY degrees Celsius is ZZ degrees Fahrenheit
XX should be a number that you assign to your first variable (the one that holds the original temperature in Fahrenheit). You must calculate YY (the calculated temperature in Celsius) from XX and you must calculate ZZ (the calculated temperature in Fahrenheit) from YY. DO NOT use XX, YY, or ZZ in your code, these are just names I used as an example in the output.
Test your application with the following values for degrees Fahrenheit: 0,32,212
Note
You may discover that the conversion from 0 to Celsius and back to Fahrenheit yields a very small, but non-zero, number. That's one of the points of this lab! Think about the data types you used and why you might get this result given those data types.
Lab 3 - Calculations Instructions: Complete each

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!