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.
#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;
}
Comments
Leave a comment