fork download
  1. //Saliha Babar CS1A Chapter 5, Page 296, #12
  2. //
  3. /************************************************************************
  4.  *
  5.  * DISPLAY A CELCIUS AND FAHRENHEIT TABLE
  6.  * ______________________________________________________________________
  7.  * This program displays a table of Celcius temperatures from 0-20 and
  8.  * their Fahrenheit equivalents.
  9.  *
  10.  * Calculation is based on the formula
  11.  * f = (9*c/5) + 32
  12.  *________________________________________________________________________
  13.  * INPUT
  14.  * f : temperature in fahrenheit
  15.  * c : temperature in celcius
  16.  *
  17.  * OUTPUT
  18.  * displays a table of celcius and fahrenheit temperatures
  19.  * *********************************************************************/
  20.  
  21. #include <iostream>
  22. #include <iomanip>
  23.  
  24. using namespace std;
  25.  
  26. int main() {
  27. int celcius; // COUNTER VARIABLE - for temperature
  28. const int minCelcius = 0 ; // INPUT - minimum temperature of Celcius
  29. const int maxCelcius = 20; // INPUT - maximum temperature of Celcius
  30. double c; // INPUT - temperature in Celcius
  31. double f; // INPUT - temperature in Fahrenheit
  32.  
  33. // Assign c to the starting value
  34. c = minCelcius;
  35.  
  36. cout << "Table of Celcius and Fahrenheit temperatures\n";
  37. cout << "-----------------------\n";
  38. cout << " celcius fahrenheit\n";
  39.  
  40. while (c <= maxCelcius )
  41. {
  42. f = (9*c/5) + 32;
  43. cout <<"\t" << c << "\t\t\t" << f << endl;
  44. c++;
  45. }
  46. return 0;
  47. }
Success #stdin #stdout 0s 5268KB
stdin
Standard input is empty
stdout
Table of Celcius and Fahrenheit temperatures
-----------------------
 celcius    fahrenheit
	0			32
	1			33.8
	2			35.6
	3			37.4
	4			39.2
	5			41
	6			42.8
	7			44.6
	8			46.4
	9			48.2
	10			50
	11			51.8
	12			53.6
	13			55.4
	14			57.2
	15			59
	16			60.8
	17			62.6
	18			64.4
	19			66.2
	20			68