In: Computer Science
Write a C++ Program. Include the Homework header.
Then prompt the user for a temperature that is in Fahrenheit for some water. Input the temperature (either an int or a double).
then output one of three statements:
if the temperature is below 32 degrees or below tell them it is ice. For example if they input 22 then the output would be:
At a temperature of 22 degrees the water would take the form of ice.
if the temperature is between 32 and 212 degrees then tell the user the water is in liquid form. For example if they input 140 the output would be:
At a temperature of 140 degrees water takes the from of liquid water.
if the temperature is greater than 212 degrees then tell the user. For example if they input 3300 the output would be: :
At a temperature of 3300 degrees water takes the form of a gas called steam.
then
Basically repeat the code. However, this time we will assume the temperature is in Celsius. So, ask for the temperature for this section of code in Celsius from the user.
And do the same description: if less than 0 degrees it is ice. If between 0 and 100 it is water and greater than 100 degrees it is steam.
Code Style:
For each section do not write three distinct if statements.
I expect to see if statements with else clauses.
When I say "I expect" it means if my expectations are not meet you get a low score.
Example of the console input and output we expect to see :
Enter the temperature in Fahrenheit : 12
At a temperature of 22 degrees the water would take the form of ice.
Enter the temperature in Celsius : 133
At a temperature of 133 degrees water takes the form of a gas called steam.
this is the code I have so far I do not know how to get it to just say liquid water or ice I cannot use the "and" or the "or"
#include <iostream>
using namespace std;
int main() {
double Fahrenheit;
double Celsius;
cout << "Enter the temperature in Fahrenheit : ";
cin >> Fahrenheit;
if (Fahrenheit < 33){
cout << "At a temperature of " << Fahrenheit << " degrees the water would take the form of ice. " << endl;
}
if (Fahrenheit < 213) {
cout << "At a temperature of " << Fahrenheit << " degrees water takes the from of liquid water." << endl;
}
else
cout << "At a temperature of " << Fahrenheit << " degrees water takes the form of a gas called steam." << endl;
cout << " Enter the temperature in Celsius : ";
cin >> Celsius;
if (Celsius <= 0){
cout << "At a temperature of " << Celsius << " degrees the water would take the form of ice. " << endl;
}
if (Celsius <= 100){
cout << "At a temperature of " << Celsius << " degrees water takes the from of liquid water." << endl;
}
else
cout << "At a temperature of " << Celsius << " degrees water takes the form of a gas called steam." << endl;
}
#include <iostream>
using namespace std;
int main() {
double Fahrenheit;
double Celsius;
cout << "Enter the temperature in Fahrenheit : ";
cin >> Fahrenheit;
if (Fahrenheit < 32){ //32 degrees or below
cout << "At a temperature of " << Fahrenheit << " degrees the water would take the form of ice. " << endl;
}
else if (Fahrenheit == 32) { //with out else if, for input 22 both
outputs will print.
cout << "At a temperature of " << Fahrenheit << " degrees water takes the from of liquid water or ice." << endl;
}
else if (Fahrenheit < 212) { //with out else if, for input 22
both outputs will print.
cout << "At a temperature of " << Fahrenheit << " degrees water takes the from of liquid water." << endl;
}
else if (Fahrenheit == 212) { //with out else if, for input 22 both
outputs will print.
cout << "At a temperature of " << Fahrenheit << " degrees water takes the from of liquid water or a gas called steam." << endl;
}
else if(Fahrenheit > 212) //this will exclude all the negative
temparatures.
cout << "At a temperature of " << Fahrenheit << " degrees water takes the form of a gas called steam." << endl;
cout << " Enter the temperature in Celsius : ";
cin >> Celsius;
if (Celsius < 0){
cout << "At a temperature of " << Celsius << " degrees the water would take the form of ice. " << endl;
}
else if (Celsius == 0) { //with out else if, for input 22 both
outputs will print.
cout << "At a temperature of " << Fahrenheit << " degrees water takes the from of liquid water or ice." << endl;
}
else if (Celsius < 100){
cout << "At a temperature of " << Celsius << " degrees water takes the from of liquid water." << endl;
}
else if (Celsius == 100) { //with out else if, for input 22 both
outputs will print.
cout << "At a temperature of " << Fahrenheit << " degrees water takes the from of liquid water or a gas called steam." << endl;
}
else
cout << "At a temperature of " << Celsius << " degrees water takes the form of a gas called steam." << endl;
}