fork download
  1. //Nicolas Ruano CS1A Ch. 5 Pp. 296 #12
  2. /******************************************************************************
  3.  * CELSIUS TO FAHRENHEIT TABLE
  4.  *
  5.  * This program displays a conversion table of Celsius to Fahrenheit
  6.  * for temperatures from 0 to 20 degrees Celsius.
  7.  *
  8.  * INPUT
  9.  * Formula: F = (9.0 / 5.0) * C + 32
  10.  *
  11.  * While it is an updated versions from chapter3, on programming challenge
  12.  *
  13.  * OUTPUT:
  14.  * Celsius and Fahrenheit values displayed side by side.
  15.  ******************************************************************************/
  16.  
  17. #include <iostream>
  18. #include <iomanip>
  19. using namespace std;
  20.  
  21. int main() {
  22. cout << "Celsius to Fahrenheit Conversion Table\n";
  23. cout << "--------------------------------------\n";
  24. cout << "Celsius\tFahrenheit\n";
  25. cout << "-------------------\n";
  26.  
  27. // Loop from 0°C to 20°C
  28. for (int celsius = 0; celsius <= 20; celsius++) {
  29. double fahrenheit = (9.0 / 5.0) * celsius + 32;
  30. cout << setw(3) << celsius << "\t"
  31. << fixed << setprecision(1) << fahrenheit << endl;
  32. }
  33.  
  34. return 0;
  35. }
  36.  
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Celsius to Fahrenheit Conversion Table
--------------------------------------
Celsius	Fahrenheit
-------------------
  0	32.0
  1	33.8
  2	35.6
  3	37.4
  4	39.2
  5	41.0
  6	42.8
  7	44.6
  8	46.4
  9	48.2
 10	50.0
 11	51.8
 12	53.6
 13	55.4
 14	57.2
 15	59.0
 16	60.8
 17	62.6
 18	64.4
 19	66.2
 20	68.0