fork download
  1. //Sam Partovi CS1A Chapter 3, P. 144, #10
  2. //
  3. /*******************************************************************************
  4. *
  5. * CONVERT CELSIUS TO FAHRENHEIT
  6. * ____________________________________________________________
  7. * This program converts temperatures in Celsius to Fahrenheit based on a user's
  8. * provided value.
  9. *
  10. * The conversion is derived from the following formula:
  11. * degreesFahrenheit = (1.80 * degreesCelsius) + 32
  12. * ____________________________________________________________
  13. *INPUT
  14. * degreesCelsius : Degrees in celsius to be converted to Fahrenheit
  15. *
  16. *OUTPUT
  17. * degreesFahrenheit : Degrees in Fahrenheit converted from Celsius
  18. *
  19. ******************************************************************************/
  20.  
  21. #include <iostream>
  22. #include <iomanip>
  23. using namespace std;
  24. int main ()
  25. {
  26. //Initialize program variables
  27. double degreesCelsius;
  28. double degreesFahrenheit;
  29.  
  30. //Prompt user for degreesCelsius input
  31. cout << "This program converts degrees Celsius to degrees Fahrenheit."
  32. << endl;
  33. cout << "---------------------------------------------------" << endl;
  34. cout << "Enter the temperature in Celsius to be converted: " << endl;
  35.  
  36. //User inputs degreesCelsius
  37. cin >> degreesCelsius;
  38.  
  39. //Perform temperature conversion
  40. degreesFahrenheit = (1.80 * degreesCelsius) + 32;
  41.  
  42. //Display the result
  43. cout << degreesCelsius << " degrees Celsius is " << setprecision(5)
  44. << degreesFahrenheit << " degrees Fahrenheit." << endl;
  45.  
  46. return 0;
  47. }
  48.  
  49.  
Success #stdin #stdout 0s 5264KB
stdin
5
stdout
This program converts degrees Celsius to degrees Fahrenheit.
---------------------------------------------------
Enter the temperature in Celsius to be converted: 
5 degrees Celsius is 41 degrees Fahrenheit.