fork download
  1. // Torrez, Elaine CS1A Chapter 5 P. 296, #12
  2.  
  3. /******************************************************************************************
  4.  *
  5.  * Celsisus to Fahrenheit Table
  6.  *
  7.  * --------------------------------------------------------------------------------
  8.  * This program displays a table showing the Celsius temperatures 0 through 20
  9.  * and their Fahrenheit equivalents. The conversion formula used is:
  10.  *
  11.  * Fahrenheit = (9.0 / 5.0) * Celsius + 32
  12.  *
  13.  * The program uses a for loop to perform and display each conversion.
  14.  * --------------------------------------------------------------------------------
  15.  *
  16.  * INPUT
  17.  * celsius : Celsius temperature (loop variable, 0 through 20)
  18.  *
  19.  * OUTPUT
  20.  * fahrenheit : Temperature converted from Celsius to Fahrenheit
  21.  *
  22.  *******************************************************************************************/
  23.  
  24. #include <iostream>
  25. #include <iomanip>
  26. using namespace std;
  27.  
  28. int main ()
  29. {
  30. double celsius; // INPUT - Celsius temperature (0–20)
  31. double fahrenheit; // OUTPUT - Converted Fahrenheit temperature
  32.  
  33. cout << "Celsius\tFahrenheit\n";
  34. cout << "-------------------\n";
  35.  
  36. // Loop from 0 through 20 Celsius
  37. for (celsius = 0; celsius <= 20; celsius++)
  38. {
  39. fahrenheit = (9.0 / 5.0) * celsius + 32;
  40. cout << fixed << setprecision(1);
  41. cout << setw(5) << celsius << "\t" << setw(8) << fahrenheit << endl;
  42. }
  43.  
  44. return 0;
  45. }
  46.  
Success #stdin #stdout 0.01s 5276KB
stdin
Standard input is empty
stdout
Celsius	Fahrenheit
-------------------
  0.0	    32.0
  1.0	    33.8
  2.0	    35.6
  3.0	    37.4
  4.0	    39.2
  5.0	    41.0
  6.0	    42.8
  7.0	    44.6
  8.0	    46.4
  9.0	    48.2
 10.0	    50.0
 11.0	    51.8
 12.0	    53.6
 13.0	    55.4
 14.0	    57.2
 15.0	    59.0
 16.0	    60.8
 17.0	    62.6
 18.0	    64.4
 19.0	    66.2
 20.0	    68.0