fork download
  1. //Ryan Shahriyarpour CS1A Carl Argila CH6 HW Q:7
  2. //
  3. /*****************************************************************************
  4.  *
  5.  * Fahrenheit to Celsius Table
  6.  *
  7.  *********************
  8.  *
  9.  * This program displays a table of Fahrenheit temperatures from 0 to 20 and
  10.  * their Celsius equivalents. The function celsius does the conversion:
  11.  * C = (5/9) * (F - 32)
  12.  *
  13.  * INPUT
  14.  * None (fixed values used)
  15.  *
  16.  * OUTPUT
  17.  * Table showing Fahrenheit temperatures and their Celsius equivalents
  18.  *
  19.  ****************************************************************************/
  20.  
  21. #include <iostream>
  22. #include <iomanip>
  23. using namespace std;
  24.  
  25. // Function prototype
  26. double celsius(double fahrenheit);
  27.  
  28. int main()
  29. {
  30. cout << "Fahrenheit\t\tCelsius\n";
  31. cout << "---------------------------------------\n";
  32.  
  33. // Display temperatures from 0 to 20 Fahrenheit
  34. for (int fahrenheit = 0; fahrenheit <= 20; fahrenheit++)
  35. {
  36. cout << fahrenheit << "\t\t\t" << fixed << setprecision(1)
  37. << celsius(fahrenheit) << endl;
  38. }
  39.  
  40. return 0;
  41. }
  42.  
  43. // Accepts a Fahrenheit temperature and returns it in Celsius
  44. // (5.0/9.0 is used instead of 5/9 to avoid integer division)
  45. double celsius(double fahrenheit)
  46. {
  47. return (5.0 / 9.0) * (fahrenheit - 32.0);
  48. }
Success #stdin #stdout 0.01s 5292KB
stdin
Standard input is empty
stdout
Fahrenheit		Celsius
---------------------------------------
0			-17.8
1			-17.2
2			-16.7
3			-16.1
4			-15.6
5			-15.0
6			-14.4
7			-13.9
8			-13.3
9			-12.8
10			-12.2
11			-11.7
12			-11.1
13			-10.6
14			-10.0
15			-9.4
16			-8.9
17			-8.3
18			-7.8
19			-7.2
20			-6.7