Write a C++ program that reads a temperature value and the letter C for Celsius or F for Fahrenheit. Print whether water is liquid, solid, or gaseous

C++ program that reads a temperature C for Celsius or F for Fahrenheit. Print whether water is liquid, solid, or gaseous

Write a C++ program that reads a temperature value and the letter C for Celsius or F for Fahrenheit. Print whether water is liquid, solid, or gaseous

Object:

Write a program that reads a temperature value and the letter C for Celsius or F for Fahrenheit. Print whether water is liquid, solid, or gaseous at the given temperature at sea level.

Code:

#include<iostream>
#include<conio.h>
using namespace std;
void main()
{
       float temp;
       char sel;
       cout<<“Select a temperature value in Celcius or Fahrenheit.\n”;
       cout<<“Press C for Celcius.\n”;
       cout<<“Press F for Fahrenheit.\n”;
       cin>>sel;
       switch (sel)
       {
       case ‘C’:
             cout<<“Enter a temperature value in Celcius: “;
             cin>>temp;
             if(temp<=0)
             {
                   cout<<“Water is solid at “<<temp<<” degree C.”;
             }
             else if(temp>=100)
             {
                   cout<<“Water is gaseous at “<<temp<<” degree C.”;
             }
             else
             {
                   cout<<“Water is liquid at “<<temp<<” degree C.”;
             }
             break;
       case ‘F’:
             cout<<“Enter a temperature value in Fahrenheit: “;
             cin>>temp;
             if(temp<=32)
             {
                   cout<<“Water is solid at “<<temp<<” degree F.”;
             }
             else if(temp>=212)
             {
                   cout<<“Water is gaseous at “<<temp<<“degree F.”;
             }
             else
             {
                   cout<<“Water is liquid at “<<temp<<” F.”;
             }       
             break;
       }
       getch();
}

#include<iostream>
#include<conio.h>
using namespace std;
void main()
{
	float temp;
	char sel;
	cout<<"Select a temperature value in Celcius or Fahrenheit.\n";
	cout<<"Press C for Celcius.\n";
	cout<<"Press F for Fahrenheit.\n";
	cin>>sel;
	switch (sel)
	{
	case 'C':
		cout<<"Enter a temperature value in Celcius: ";
		cin>>temp;
		if(temp<=0)
		{
			cout<<"Water is solid at "<<temp<<" degree C.";
		}
		else if(temp>=100)
		{
			cout<<"Water is gaseous at "<<temp<<" degree C.";
		}
		else
		{
			cout<<"Water is liquid at "<<temp<<" degree C.";
		}
		break;
	case 'F':
		cout<<"Enter a temperature value in Fahrenheit: ";
		cin>>temp;
		if(temp<=32)
		{
			cout<<"Water is solid at "<<temp<<" degree F.";
		}
		else if(temp>=212)
		{
			cout<<"Water is gaseous at "<<temp<<"degree F.";
		}
		else
		{
			cout<<"Water is liquid at "<<temp<<" F.";
		}
		break;
	}
	getch();
}

Output:

Write a C++ program that reads a temperature value and the letter C for Celsius or F for Fahrenheit. Print whether water is liquid, solid, or gaseous

4 thoughts on “Write a C++ program that reads a temperature value and the letter C for Celsius or F for Fahrenheit. Print whether water is liquid, solid, or gaseous”

  1. Pingback: C++ Program one large chemical company pays its salespeople on a commission basis

  2. Pingback: C++ projects for beginners with source code - Codeboks

Leave a Comment

Your email address will not be published. Required fields are marked *