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.  
  23. using namespace std;
  24.  
  25. int main() {
  26. int celcius; // COUNTER VARIABLE - for temperature
  27. const int minCelcius = 0 ; // INPUT - minimum temperature of Celcius
  28. const int maxCelcius = 20; // INPUT - maximum temperature of Celcius
  29. double c; // INPUT - temperature in Celcius
  30. double f; // INPUT - temperature in Fahrenheit
  31.  
  32. // Assign c to the starting value
  33. c = minCelcius;
  34.  
  35. cout << "Table of Celcius and Fahrenheit temperatures\n";
  36. cout << "-----------------------\n";
  37. cout << " celcius fahrenheit\n";
  38.  
  39. while (c <= maxCelcius )
  40. {
  41. f = (9*c/5) + 32;
  42. cout <<"\t" << c << "\t\t\t" << f << endl;
  43. c++;
  44. }
  45. return 0;
  46. }
Success #stdin #stdout 0s 5280KB
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