Freezing and Boiling Points Program C++

The following table lists the freezing and boiling points of several substances.

 

Write a program that asks the user to enter a temperature, and then shows all the substances that will freeze at that temperature and all that will boil at that temperature. For example, if the user enters –20 the program should report that water will freeze and oxygen will boil at that temperature.

 

Substance     Freezing Point (°F)    Boiling Point (°F)

 

Ethyl alcohol                 –173                            172

 

Mercury                         –38                             676

 

Oxygen                        –362                           –306

 

Water                              32                             212

 

Solution:

/* C Program that reads in a temperature and finds whether substance has reached its boiling or freezing point */

#include <stdio.h>
#include <stdlib.h>

//Main Program
int main()
{
int temperature;

//Read temperature from console
printf(“\n Enter temperature (in Fahrenheit): “);
scanf(“%d”, &temperature);

//Handling freezing point case of Ethyl alcohol
if(temperature <= -173)
printf(“\n Ethyl alcohol will freeze. \n”);

//Handling boiling point case of Ethyl alcohol
if(temperature >= 172)
printf(“\n Ethyl alcohol will boil. \n”);

//Handling freezing point case of Mercury
if(temperature <= -38)
printf(“\n Mercury will freeze. \n”);

//Handling boiling point case of Mercury
if(temperature >= 676)
printf(“\n Mercury will boil. \n”);

//Handling freezing point case of Oxygen
if(temperature <= -362)
printf(“\n Oxygen will freeze. \n”);

//Handling boiling point case of Oxygen
if(temperature >= -306)
printf(“\n Oxygen will boil. \n”);

//Handling freezing point case of Water
if(temperature <= 32)
printf(“\n Water will freeze. \n”);

//Handling boiling point case of Water
if(temperature >= 212)
printf(“\n Water will boil. \n”);

return 0;
}