fork download
  1. // Cenyao Huang CS1A Homework 5, p. 224, #20
  2.  
  3. /******************************************************************************************************
  4. * DISPLAY FREEZING AND BOILING SUBSTANCES
  5. *
  6. * This program displays what substances will freeze and boil at the specific
  7. * temperature inputted.
  8. *
  9. * Input
  10. * temp : the value of the temperature entered
  11. *
  12. * Output
  13. * It will display the substances that will boil and freeze at that temperature
  14. *
  15. ****************************************************************************************************/
  16.  
  17. #include <iostream>
  18. #include <string>
  19. using namespace std;
  20.  
  21. int main() {
  22.  
  23. // assign variables
  24. float temp;
  25. int count = 0;
  26.  
  27. // ask for and display temperature
  28. cout << "Please enter a temperature in fahrenheit: ";
  29. cin >> temp;
  30. cout << temp << "°F" << endl;
  31.  
  32. // display substances that will boil
  33. if (temp >=172) {
  34. cout << "Ethyl alcohol will boil." << endl;
  35. count += 1;
  36. }
  37. if (temp >=676) {
  38. cout << "Mercury will boil." << endl;
  39. count += 1;
  40. }
  41. if (temp >= -306) {
  42. cout << "Oxygen will boil." << endl;
  43. count += 1;
  44. }
  45. if (temp >= 212) {
  46. cout << "Water will boil." << endl;
  47. count += 1;
  48. }
  49.  
  50. // display substances that will freeze
  51. if (temp <= -173) {
  52. cout << "Ethyl alcohol will freeze." << endl;
  53. count+=1;
  54. }
  55. if (temp <= -38) {
  56. cout << "Mercury will freeze." << endl;
  57. count+=1;
  58. }
  59. if (temp <= -362) {
  60. cout << "Oxygen will freeze."<< endl;
  61. count+=1;
  62. }
  63. if (temp <= 32) {
  64. cout << "Water will freeze." << endl;
  65. count+=1;
  66. }
  67.  
  68. // display message if none of the substances boil or freeze
  69. if (count == 0)
  70. cout << "None of the substances will boil or freeze at this temperature.";
  71.  
  72. return 0;
  73. }
Success #stdin #stdout 0s 5328KB
stdin
-10
stdout
Please enter a temperature in fahrenheit: -10°F
Oxygen will boil.
Water will freeze.