Link to website that explains conditionals:
http://www.cprogramming.com/tutorial/lesson2.html
Link to the code:
https://github.com/cortesivan96/WSQs/blob/master/Temperature
]]>This is my code:
tempF = float(input("Give me a temperature in Fahrenheit. "))
tempC = float( 5.0 * (tempF - 32) / 9.0)
print("The temperature in Celsius is",tempC)
if tempC <= 0:
print("Water freezes at this temperature.")
elif 0 < tempC < 100:
print("Water is liquid at this temperature.")
else:
print("Water boils at this temperature.")
]]>We are going to see how well we’ve understood the “if” and “else” conditionals, you know, those pesky words from fifth grade Grammar:
First up we have the code. Notice that there is a void type function before the main function. This was used by me in order to see if I knew how to correctly use those, and it turned out well, but the code can do without a void type function, having the “if” and “else” conditionals inside the main funciton.
As usual, we compile in Cygwin to check for any mistakes and happily find out there are none, giving the program the value 289 as Fahrenheit temperature.
It does work! We get the conversion from Fahrenheit to Celsius and a message indicating that water reaches its boiling point at this temperature. Then we try with a lower value and get a message informing us that this is too low for water to become a gas.
]]>We are going to see how well we’ve understood the “if” and “else” conditionals, you know, those pesky words from fifth grade Grammar:
First up we have the code. Notice that there is a void type function before the main function. This was used by me in order to see if I knew how to correctly use those, and it turned out well, but the code can do without a void type function, having the “if” and “else” conditionals inside the main funciton.
As usual, we compile in Cygwin to check for any mistakes and happily find out there are none, giving the program the value 289 as Fahrenheit temperature.
It does work! We get the conversion from Fahrenheit to Celsius and a message indicating that water reaches its boiling point at this temperature. Then we try with a lower value and get a message informing us that this is too low for water to become a gas.
]]>Para este código me sirvió mucho un curso de programación básica que tomé en prepa. Aunque era en python, se parece mucho en el sentido lógico y algo en sintaxis. En el código , en la parte de la condición, pude haber simplificado la fórmula para los grados celsius en una variable, pero como de todos mods así funciona bien, decidí dejarlo así.
Este fue mi código:
// WSQ05 Fahrenheit to Celsius
#include <iostream>
using namespace std;
int main() {
double x;
cout <<“Dame la temperatura en Fahrenheit ” <<endl;
cin >>(x);
cout << “La temperatura en Celsius es ” <<(5*(x-32)/9) <<endl;
if (5*(x-32)/9<100)
cout <<“El agua no ebulle a esta temperatura” <<endl;
else
cout <<“El agua ebulle a esta temperatura” <<endl;
return 0;
}
This is what happens when you run it and choose a temperature in fahrenheit:
This is what happens when you give a temperature in celcius:
]]>#include <iostream>
using namespace std;
int main(){
double x;
cout << “Introducir grados farenheitn”;
cin >> x;
double y = (5.0/9.0) * (x – 32.0);
cout << “La temperatura es = ” << y << ” C°” << “n”;
if (y >= 100.0){
cout << “El agua es vapor”;}
else if (y <= 0.0){
cout << “El agua es solida”;}
else if (y){
cout << “El agua es liquida”;}
return 0;
}
This is the program.
]]>#include <iostream>
using namespace std;
int main(){
double x;
cout << “Introducir grados farenheitn”;
cin >> x;
double y = (5.0/9.0) * (x – 32.0);
cout << “La temperatura es = ” << y << ” C°” << “n”;
if (y >= 100.0){
cout << “El agua es vapor”;}
else if (y <= 0.0){
cout << “El agua es solida”;}
else if (y){
cout << “El agua es liquida”;}
return 0;
}
This is the program.
]]>