Answer to Question #180744 in C++ for fiey

Question #180744

Water is solid if its temperature is 273 Kelvin and below. It is liquid when its temperature is between 273 Kelvin and 373 Kelvin. When it is 373 Kelvin and higher, it becomes gas. Create a program that will ask for the temperature of the water in Kelvin, and display the its phase. Use Boolean operators and If statements.


1
Expert's answer
2021-04-13T02:40:02-0400
#include <iostream>
using namespace std;


int main()
{
    bool solid = false, liquid = false, gas = false;
    int temperature;
    cout<<"Enter the temperature in Kelvin: ";
    cin>>temperature;
    //Check the state using if statements
    if(temperature <= 273 )
    {
        solid = true;
    }
    else if( (temperature > 273) && (temperature < 373))
    {
        liquid = true;
    }
    else if( temperature >= 373 )
    {
        gas = true;
    }


    //Display the state based on corresponding boolean status
    if(solid)
    {
        cout<<"The water is in solid state"<<endl;
    }
    if(liquid)
    {
        cout<<"The water is in liquid state"<<endl;
    }
    if(gas)
    {
        cout<<"The water is in gaseous state"<<endl;
    }
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS