fork download
  1. // Chapter 4 - Programming Challenge #20
  2. // Freezing and Boiling Points
  3. // This program asks the user to enter a temperature
  4. // in degrees Fahrenheit. It then determines which
  5. // substances will freeze and which substances will
  6. // boil at that temperature.
  7.  
  8. #include <iostream>
  9. using namespace std;
  10.  
  11. int main()
  12. {
  13. // Constants for the freezing points of each substance
  14. const double ETHYL_FREEZING = -173;
  15. const double MERCURY_FREEZING = -38;
  16. const double OXYGEN_FREEZING = -362;
  17. const double WATER_FREEZING = 32;
  18.  
  19. // Constants for the boiling points of each substance
  20. const double ETHYL_BOILING = 172;
  21. const double MERCURY_BOILING = 676;
  22. const double OXYGEN_BOILING = -306;
  23. const double WATER_BOILING = 212;
  24.  
  25. // Variable to store the temperature entered by the user
  26. double temperature;
  27.  
  28. // Get the temperature from the user
  29. cout << "Enter a temperature in degrees Fahrenheit: ";
  30. cin >> temperature;
  31.  
  32. // Check which substances will freeze at this temperature.
  33. // A substance will freeze if the temperature is at or
  34. // below its freezing point.
  35. if (temperature <= ETHYL_FREEZING)
  36. {
  37. cout << "Ethyl alcohol will freeze." << endl;
  38. }
  39.  
  40. if (temperature <= MERCURY_FREEZING)
  41. {
  42. cout << "Mercury will freeze." << endl;
  43. }
  44.  
  45. if (temperature <= OXYGEN_FREEZING)
  46. {
  47. cout << "Oxygen will freeze." << endl;
  48. }
  49.  
  50. if (temperature <= WATER_FREEZING)
  51. {
  52. cout << "Water will freeze." << endl;
  53. }
  54.  
  55. // Check which substances will boil at this temperature.
  56. // A substance will boil if the temperature is at or
  57. // above its boiling point.
  58. if (temperature >= ETHYL_BOILING)
  59. {
  60. cout << "Ethyl alcohol will boil." << endl;
  61. }
  62.  
  63. if (temperature >= MERCURY_BOILING)
  64. {
  65. cout << "Mercury will boil." << endl;
  66. }
  67.  
  68. if (temperature >= OXYGEN_BOILING)
  69. {
  70. cout << "Oxygen will boil." << endl;
  71. }
  72.  
  73. if (temperature >= WATER_BOILING)
  74. {
  75. cout << "Water will boil." << endl;
  76. }
  77.  
  78. return 0;
  79. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Enter a temperature in degrees Fahrenheit: Water will freeze.
Oxygen will boil.