Question

In: Computer Science

Write a C++ Program. Include the Homework header. Then prompt the user for a temperature that...

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;

}

Solutions

Expert Solution

#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;

}


Related Solutions

IN C This assignment is to write a program that will prompt the user to enter...
IN C This assignment is to write a program that will prompt the user to enter a character, e.g., a percent sign (%), and then the number of percent signs (%) they want on a line. Your program should first read a character from the keyboard, excluding whitespaces; and then print a message indicating that the number must be in the range 1 to 79 (including both ends) if the user enters a number outside of that range. Your program...
Write a C program Your program will prompt the user to enter a value for the...
Write a C program Your program will prompt the user to enter a value for the amount of expenses on the credit card. Retrieve the user input using fgets()/sscanf() and save the input value in a variable. The value should be read as type double. The user may or may not enter cents as part of the input. In other words, expect the user to enter values such as 500, 500.00 and 500.10. The program will then prompt the user...
write a program to perform the following in C Your program should prompt the user to...
write a program to perform the following in C Your program should prompt the user to enter ten words, one at a time, which are to be stored in an array of strings. After all of the words have been entered, the list is to be reordered as necessary to place the words into alphabetical order, regardless of case. Once the list is in alphabetical order, the list should be output to the console in order. The program should execute...
In C++ Please, using only the libraries given in this homework prompt, Write a program that...
In C++ Please, using only the libraries given in this homework prompt, Write a program that (1) prompts for two integers, (2) prints out their sum, (3) prints out the first divided by the second, and (4) prints out the natural log of the first number raised to the power of the second number. #include <iostream> #include <iomanip> using namespace std; int main() { <your answer goes here> return 0; }
1. Write a program in C++ to find the factorial of a number. Prompt the user...
1. Write a program in C++ to find the factorial of a number. Prompt the user for a number and compute the factorial by using the following expression. Use for loops to write your solution code. Factorial of n = n! = 1×2×3×...×n; where n is the user input. Sample Output: Find the factorial of a number: ------------------------------------ Input a number to find the factorial: 5 The factorial of the given number is: 120 2. Code problem 1 using While...
Write a C program that prompt the user to enter 10 numbers andstores the numbers...
Write a C program that prompt the user to enter 10 numbers and stores the numbers in an array. Write a function, smallestIndex, that takes as parameters an int array and its size and return the index of the first occurrence of the smallest element in the array.The main function should print the smallest number and the index of the smallest number.
Write a C++ program that prompt the user to enter 10 numbers andstores the numbers...
Write a C++ program that prompt the user to enter 10 numbers and stores the numbers in an array. Write a function, smallestIndex, that takes as parameters an int array and its size and return the index of the first occurrence of the smallest element in the array.The main function should print the smallest number and the index of the smallest number.
C++ PLEASE Write a program to prompt the user to display the following menu: Guess-Number                       ...
C++ PLEASE Write a program to prompt the user to display the following menu: Guess-Number                        Concat-names             Quit If the user selects Guess-number, your program needs to call a user-defined function called int guess-number ( ). Use random number generator to generate a number between 1 – 100. Prompt the user to guess the generated number and print the following messages. Print the guessed number in main (): Guess a number: 76 96: Too large 10 Too small 70 Close...
C++ Code Writing prompt: Grade Calculation: Write a program that asks the user to enter in...
C++ Code Writing prompt: Grade Calculation: Write a program that asks the user to enter in a number greater than or equal to zero and less than or equal to 100. If they do not you should alert them and end the program. Next, determine the letter grade associated with the number. For example, A is any grade between 90 and 100. Report the letter grade to the user.
(java))Write a “Temperature Conversion” program. Declare choice, tempIn, tempOut variables Prompt the user with the messages...
(java))Write a “Temperature Conversion” program. Declare choice, tempIn, tempOut variables Prompt the user with the messages to choose: 1) Centigrade to Fahrenheit, 2) Fahrenheit to centigrade. Prompt the user for temperature value (tempIn) to convert. Calculate new tempOut. The calculation of the new tempOUT depends on choice 1 or 2 above.\ ( Lookup up the C to F formula online, loop up the F to C formula online ) Print out the the F and the C temps. Be sure...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT