fork download
  1. //Cameron Pham CS1A Chapter 4, P. 224, #20
  2. //
  3. /*******************************************************************************
  4. *
  5. * Calculate Freezing and Boiling Points
  6. *
  7. *______________________________________________________________________________
  8. * This program accepts a value for temperature and then determines which
  9. * substances would freeze at a given temperature and which would boil at
  10. * a given temperature.
  11. *
  12. * INPUT
  13. * Temperature in Fahrenheit
  14. *
  15. * OUTPUT
  16. * List of substances that freeze at given temperature
  17. * List of substances that boil at given 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. cout << endl;
  40. cout << "You entered " << temperature << "." << endl;
  41.  
  42. // Check which substances freeze at this temperature
  43. cout << "\nAt " << temperature << " degrees, the following will freeze:";
  44. cout << endl;
  45. if (temperature <= ETHYL_FREEZE)
  46. cout << "Ethyl alcohol" << endl;
  47. if (temperature <= MERCURY_FREEZE)
  48. cout << "Mercury" << endl;
  49. if (temperature <= OXYGEN_FREEZE)
  50. cout << "Oxygen" << endl;
  51. if (temperature <= WATER_FREEZE)
  52. cout << "Water" << endl;
  53.  
  54. // Check which substances boil at this temperature
  55. cout << "\nAt " << temperature << " degrees, the following will boil:";
  56. cout << endl;
  57. if (temperature >= ETHYL_BOIL)
  58. cout << "Ethyl alcohol" << endl;
  59. if (temperature >= MERCURY_BOIL)
  60. cout << "Mecury" << endl;
  61. if (temperature >= OXYGEN_BOIL)
  62. cout << "Oxygen" << endl;
  63. if (temperature >= WATER_BOIL)
  64. cout << "Water" << endl;
  65.  
  66. return 0;
  67. }
Success #stdin #stdout 0s 5316KB
stdin
-20
stdout
Enter a temperature (in Fahrenheit): 
You entered -20.

At -20 degrees, the following will freeze:
Water

At -20 degrees, the following will boil:
Oxygen