C++ program that reads a temperature 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(); }
Pingback: C++ Program one large chemical company pays its salespeople on a commission basis
Pingback: C++ projects for beginners with source code - Codeboks
WONDERFUL Post. thanks for share.
Loving the info on this website, you have done an outstanding job on the content.