/* C++ Programming, Example answer, Exercise 2, Sheet 2  */

/* Author: Rob Miller and William Knottenbelt
   Program last changed: 30th September 2003    */

/* This program prints out a conversion table of temperatures, after
prompting the user for upper and lower bounds in Fahrenheit, and the
temperature difference between table entries. */ 

#include <iostream>
using namespace std;

int main() 
{	
	int fahr = 0; 
	double celsius = 0;
	int lower = 0;
	int upper = 0;
	int step = 1;

	/* prompt user for table specification */
	cout << "This program prints out a conversion table of temperatures.\n\n";
	cout << "Enter the minimum (whole number) temperature\n";
	cout << "you want in the table, in Fahrenheit: ";
	cin >> lower;
	cout << "Enter the maximum temperature you want in the table: ";
	cin >> upper;
	cout << "Enter the temperature difference you want between table entries: ";
	cin >> step;
	cout << "\n\n";
	
	/* echo the input */
	cout << "Tempertature conversion table from " << lower << " Fahrenheit\n";
	cout << "to " << upper << " Fahrenheit, in steps of " << step << " Fahrenheit:\n\n";
	
	/* Print table heading */
	cout.width(15);
	cout << "Fahrenheit";
	cout.width(17);
	cout << "Celsius";
        cout.width(20);
        cout << "Absolute Value\n\n";

	/* set format of individual values */
	cout.precision(2); 
	cout.setf(ios::fixed); 

	/* print table from lower to upper */
	for (fahr = lower ; fahr <= upper ; fahr += step) {
                cout << "   ";
		cout.width(15);
		cout << fahr;
		celsius = (static_cast<double>(5)/9) * (fahr - 32);
		cout.width(15);
		cout << celsius;
                cout.width(15);
                cout <<  celsius + 273.15 << endl;
	}
	return 0;
}
