Temperature (WSQ05)

This homework is about converting Fahrenheit degrees to Celsius. The deal is that we need to ask the user for the temperature in Fahrenheit, and the code does the rest to convert that quantity to Celsius.

As I need the user to give me the number, I enter an input in my program, and I assign a variable to it. I will assing the variable “f”

temperature 01 - copia

To do the math process, we need to create another variable, so then a result can be printed.

temperature 01

My new variable is “c”, followed by the operation that will convert the Fahrenheit degrees to Celsius. I should be careful in this part because at the beginning I wasn’t writing the right syntax, so I had to try many times to get the right result, my advice is: be careful with the parentheses.

The formula is  C = 5 ∗ (F − 32)/9 we just need to transform that in a code. I’m telling the program that I just need the integer result with the “int” label, before the whole sentence.
Then I need my “f” variable. Let’s convert all our numbers to integers, I won’t use any float today, so I’m converting my “f” variable to an integer “int”.

temperature 01 - copia (2)

Let’s print the result. To include the variables in the sentence, we must close the (“), type a (,) and then the variable. Like in the picture above.

temperature 01 - copia (2)

The rest is easy. It’s necessary to indicate if the temperature that the user give us would make the water boil, freexe or none of them. We get that with the “if” label.

In the first “if” sentence, I needed to indicate the “range” in which the water is neither boiling nor freezing. We print the sentence that will indicate the result to our user. NOTE: you should type

temperature 02

so the sentence that you want for THAT “if” line just get printed if that condition is accomplished.

The second and the third line just need a (<>) comparison, and the rest is the same than the first one.

The result is this:

temperature 02

Here’s my code.

See you in the next post…

 

CC BY-SA 4.0 Temperature (WSQ05) by paogarcia2401 is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.