fork download
  1. //Zachary Abdollahi CS1A Chapter 4, P. 224, #20
  2. //
  3. /*******************************************************************************
  4.  *
  5.  * CALCULATE FREEZING AND BOILING POINTS
  6.  *
  7.  *______________________________________________________________________________
  8.  * This program asks the user to enter a temperature and then reports which
  9.  * substances would freeze at a given temperature and which would boil at
  10.  * a given temperature.
  11.  *
  12.  * INPUT
  13.  * temperature : Temperature entered by the user (in Fahrenheit)
  14.  *
  15.  * OUTPUT
  16.  * List of substances that freeze at that temperature
  17.  * List of substances that boil at that temperature
  18.  *
  19.  ******************************************************************************/
  20. #include <iostream>
  21. using namespace std;
  22. int main()
  23. {
  24. double temperature; //INPUT - Temperature entered by the user
  25.  
  26. // Freezing and boiling points for each substance
  27. const double ETHYL_FREEZE = -173.0;
  28. const double ETHYL_BOIL = 172.0;
  29. const double MERCURY_FREEZE = -38.0;
  30. const double MERCURY_BOIL = 676.0;
  31. const double OXYGEN_FREEZE = -362.0;
  32. const double OXYGEN_BOIL = -306.0;
  33. const double WATER_FREEZE = 32.0;
  34. const double WATER_BOIL = 212.0;
  35.  
  36. // Get input from user
  37. cout << "Enter a temperature (in Fahrenheit): ";
  38. cin >> temperature;
  39.  
  40. // Check which substances freeze at this temperature
  41. cout << "\nAt " << temperature << " degrees, the following will freeze:" << endl;
  42. if (temperature <= ETHYL_FREEZE)
  43. cout << "Ethyl alcohol" << endl;
  44. if (temperature <= MERCURY_FREEZE)
  45. cout << "Mercury" << endl;
  46. if (temperature <= OXYGEN_FREEZE)
  47. cout << "Oxygen" << endl;
  48. if (temperature <= WATER_FREEZE)
  49. cout << "Water" << endl;
  50.  
  51. // Check which substances boil at this temperature
  52. cout << "\nAt " << temperature << " degrees, the following will boil:" << endl;
  53. if (temperature >= ETHYL_BOIL)
  54. cout << "Ethyl alcohol" << endl;
  55. if (temperature >= MERCURY_BOIL)
  56. cout << "Mecury" << endl;
  57. if (temperature >= OXYGEN_BOIL)
  58. cout << "Oxygen" << endl;
  59. if (temperature >= WATER_BOIL)
  60. cout << "Water" << endl;
  61.  
  62. return 0;
  63. }
Success #stdin #stdout 0s 5316KB
stdin
-20
stdout
Enter a temperature (in Fahrenheit): 
At -20 degrees, the following will freeze:
Water

At -20 degrees, the following will boil:
Oxygen