This program is intented to be an intruction to conditionals statements if and else.
The program consist in asking the Temperature in Farenheit to the user, transform it into Celcius, print it in the screen and then letting the user know if water would be boiling or not.
The source code is this:
temp=float(input(“What is the temperature in Fahrenheit? “))
temp=5*(temp-32)/9
print(temp,”ºC”)
if(temp<100):
print(“Water is not boiling”)
else:
print(“Water is boiling”)
Where we can see how we ask for the temperature to the user and then store it in the variable temp, wich in this case I have declared it as a float, just to get decimals nothing more.
Then we apply the formula to convert Farenheit into Celcius and store it in the same variable we have created before. If we wanted to recieve an integer answer we could use a floor division // instead of the /.
Then comes the conditionals, the if statement evaluates the expression inside the parenthesis and if the expression returns a true value it execute the code below. The else statement is used to have an alternative when the if statemen expresion returns a false, if it does it executes the block of code below that has the appropiate identation.
Here you can have more information and examples to the use of conditional statements.
]]>1 min read
Hey programmers!
Hereby I show you a program that I wrote #WSQ05, is my first code using “is” and “else”,
I hope it will help you and if you have any problem let me a comment.
#Temperature #TC1017
Here is my code: #333333; font-family: Georgia, ‘Bitstream Charter’, serif; line-height: 23.7999992370605px;”> #333333; font-family: Georgia, ‘Bitstream Charter’, serif;”>https:/
#333333; font-family: Georgia, ‘Bitstream Charter’, serif;”>The only question I have is, Do we can do this program using switch instead “if,else”?
]]>1 min read
Before you start reading my post, please click this link to listen to the correct music for this: Link to video
#WSQ05 #Temperature #TC1017 #CCourses
Code down below:
//Mauricio Cooper A01630042
#include <iostream>
using namespace std;
int C,F;
int main () {
cout << endl;
cout << “Enter a Fahrenheit Degrees Temperature” << endl;
cout << endl;
cin >> F ;
cout << endl;
C=5*(F-32)/9;
cout << “Your temperature in Celsius degrees is: ” << C << endl;
cout << endl;
if (C >= 100){
cout << “Water would boil at this temperature. This crap is hot.”;
}
if (C <=0) {
cout << “Water would freeze at this temperature. Cold as your GF.”;
}
if (C > 0 && C < 100) {
cout << “Water neither freeze nor boil. Fresh as fuck.”;
}
cout << endl;
return 0;
}
]]>
1 min read
For this activity we have to ask a temperature in Fahrenheit and convert it to Celsius.
First of all, I found useful information in our course book, in the part 4.2 Conditional execution; also we have to declare float variables because we are not using integer values, in this page I found some information about that:
http:/
The new thing that I learned in this activity is how to use the conditional “if/else”, the structure is really simple. In the condition “if” you only have to write a TRUE condition for an action, and you have to put “else” to indicate a FALSE condition for the same action.
In the following link you will find my c++ code:
https:/
And I will share some pictures, one of them is my c++ code and the other one is the program working.
]]>