fork download
  1. //Jeremy Huang CS1A Chapter 4, P. 224, #20
  2. //
  3. /**************************************************************
  4.  *
  5.  * CALCULATE FREEZE OR BOIL SUBSTANCE
  6.  * ____________________________________________________________
  7.  * This program takes user input of a temperature and outputs
  8.  * which substances will freeze or boil at the given
  9.  * temperature.
  10.  * ____________________________________________________________
  11.  * INPUT
  12.  * temperature : temperature which user inputs
  13.  *
  14.  * OUTPUT
  15.  * N/A :cout outputs which will freeze or boil
  16.  *
  17.  **************************************************************/
  18. #include <iostream>
  19. using namespace std;
  20.  
  21. int main() {
  22. const int ETHYL_ALCOHOL_FREEZE = -173;
  23. const int ETHYL_ALCOHOL_BOIL = 172;
  24. const int MERCURY_FREEZE = -38;
  25. const int MERCURY_BOIL = 676;
  26. const int OXYGEN_FREEZE = -362;
  27. const int OXYGEN_BOIL = -306;
  28. const int WATER_FREEZE = 32;
  29. const int WATER_BOIL = 212;
  30.  
  31. int temperature; //INPUT - temperature which user inputs
  32.  
  33. //User Input
  34. cout << "Enter a temperature in Fahrenheit: "<<endl;
  35. cin >> temperature;
  36.  
  37. //Output Result
  38. cout << "At " << temperature << "°F, the following substances will freeze:" << endl;
  39.  
  40. if (temperature <= ETHYL_ALCOHOL_FREEZE) {
  41. cout << "- Ethyl alcohol" << endl;
  42. }
  43. if (temperature <= MERCURY_FREEZE) {
  44. cout << "- Mercury" << endl;
  45. }
  46. if (temperature <= OXYGEN_FREEZE) {
  47. cout << "- Oxygen" << endl;
  48. }
  49. if (temperature <= WATER_FREEZE) {
  50. cout << "- Water" << endl;
  51. }
  52.  
  53. cout << "At " << temperature << "°F, the following substances will boil:" << endl;
  54.  
  55. if (temperature >= ETHYL_ALCOHOL_BOIL) {
  56. cout << "- Ethyl alcohol" << endl;
  57. }
  58. if (temperature >= MERCURY_BOIL) {
  59. cout << "- Mercury" << endl;
  60. }
  61. if (temperature >= OXYGEN_BOIL) {
  62. cout << "- Oxygen" << endl;
  63. }
  64. if (temperature >= WATER_BOIL) {
  65. cout << "- Water" << endl;
  66. }
  67.  
  68. return 0;
  69. }
Success #stdin #stdout 0s 5308KB
stdin
-600
stdout
Enter a temperature in Fahrenheit: 
At -600°F, the following substances will freeze:
- Ethyl alcohol
- Mercury
- Oxygen
- Water
At -600°F, the following substances will boil: