fork download
  1. //Charlotte Davies-Kiernan CS1A Chapter 6 P. 370 #7
  2. //
  3. /******************************************************************************
  4.  *
  5.  * Compute Celsius Conversion
  6.  * ____________________________________________________________________________
  7.  * This program will convert a temperature from Farenheit to Celsius. Then the
  8.  * program will display a table of the Farenheit temperatures 0 through 20 and
  9.  * their Celsius equivalents.
  10.  *
  11.  * Formula used:
  12.  * celsius = 5.0/9.0 (farenheit - 32)
  13.  * ____________________________________________________________________________
  14.  * Input
  15.  * farenheit //Temperature in Farenheit that needs to be converted
  16.  * Output
  17.  * userCelsius //The Farneheit temperature converted into Celsius
  18.  * celsiusTemp //The Celsius conversions in the table from the Farenheit degrees 0 through 20
  19.  *****************************************************************************/
  20. #include <iostream>
  21. #include <iomanip>
  22. using namespace std;
  23. //Function Prototype
  24. float celsius(float farenheit);
  25.  
  26. int main() {
  27. //Data Dictionary
  28. float farenheit; //INPUT - Temperature in Farenheit that needs to be converted
  29. float userCelsius; //OUPUT - The Farenheit temperature converted into Celsius
  30. float celsiusTemp; //OUTPUT - The Celsius conversions in the table from the Farenheit degrees 0 through 20
  31. cout << fixed << setprecision(2);
  32. cout << "Enter a Farenheit temperature to convert: " << endl;
  33. cin >> farenheit;
  34. userCelsius = celsius(farenheit);
  35. cout << farenheit << "°F is equal to " << userCelsius << "°C" << endl;
  36. cout << "Farenheit Celsius" << endl;
  37. //Loop through Farenheit values 0 to 20
  38. for (int i = 0; i <= 20; i++){
  39. celsiusTemp = celsius(i);
  40. cout << setw(6) << i << "°F" << setw(14) << celsiusTemp << "°C" << endl;
  41. }
  42. return 0;
  43. }
  44. float celsius(float farenheit){
  45. return (5.0/9.0) * (farenheit - 32.0);
  46. }
Success #stdin #stdout 0.01s 5280KB
stdin
-4
stdout
Enter a Farenheit temperature to convert: 
-4.00°F is equal to -20.00°C
Farenheit     Celsius
     0°F        -17.78°C
     1°F        -17.22°C
     2°F        -16.67°C
     3°F        -16.11°C
     4°F        -15.56°C
     5°F        -15.00°C
     6°F        -14.44°C
     7°F        -13.89°C
     8°F        -13.33°C
     9°F        -12.78°C
    10°F        -12.22°C
    11°F        -11.67°C
    12°F        -11.11°C
    13°F        -10.56°C
    14°F        -10.00°C
    15°F         -9.44°C
    16°F         -8.89°C
    17°F         -8.33°C
    18°F         -7.78°C
    19°F         -7.22°C
    20°F         -6.67°C