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();
}

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

M.A Siddiqui

Hi, I am M.A Siddiqui. I'm a Computer Science Student, In this website, I'm teaching you Multiple languages and provides Projects and other Subjects Notes.

You may also like...

2 Responses

  1. April 16, 2020

    […] Another Project : Write a C++ program that reads a temperature value and the letter C for Celsius or… […]

  2. June 14, 2020

    […] Write a C++ program that reads a temperature value and the letter C for Celsius or F for Fahrenheit.… […]

Leave a Reply

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