main
  1//: GoodDocs.cpp
  2
  3/* 
  4 Title: GoodDocsF.cpp
  5 Description: Temperature Conversion Program
  6 Date: December 8, 2013
  7 Author: Richard S. Huntrods
  8 Version: 1.0
  9 Copyright: 2013 Richard S. Huntrods
 10*/
 11
 12/*
 13 DOCUMENTATION
 14 
 15 Program Purpose:
 16 	Demonstrate proper format for documentation, test plans and comments.
 17 	Also demonstrate user prompts, keyboard input, simple calculations and output,
 18 	specifically converting temperatures from F to C.
 19
 20 Compile (assuming mingw compiler and opened command prompt): g++ -o GoodDocsF GoodDocsF.cpp
 21 Execution (in a Command Prompt window): GoodDocsF.exe (or just GoodDocsF)
 22 
 23 Classes: none
 24
 25 Variables:
 26 	input_units (char) = C or F to designate temperature units for the supplied input temperature.
 27 	output_units (char) = C or F to designate temperature units desired for the output conversion,
 28 	input_temp (float) = real (decimal) number supplied by user which is the input temperature.
 29 	output_temp (float) = calculated output temperature in output_units as a real (decimal) number.
 30
 31 Formulae:
 32 	The formula for converting temperatures from Fahrenheit to Celcius is:
 33 	T(C) = (T(F) - 32.0) * 5.0 / 9.0;
 34 	The formula for converting temperatures from Celcius to Fahrenheit is:
 35 	T(F) = (T(C) * 9.0 / 5.0) + 32.0
 36
 37 	It is important to use decimal numbers especially in the division to avoid integer devision.
 38 	It is also important use use the parenthesis to enforce calculation order.
 39*/
 40
 41/*
 42 TEST PLAN
 43 
 44 Normal case 1:
 45 	>What is the input temperature? 32
 46 	>What are the units of the input temperature (C for Celcius or F for Fahrenheit)? F
 47 	>Your input temperature is 32F which is 0C.
 48
 49 Normal case 2:
 50 	>What is the input temperature? 100
 51 	>What are the units of the input temperature (C for Celcius or F for Fahrenheit)? C
 52 	>Your input temperature is 100C which is 212F.
 53
 54 Bad Data case 1 (temperature out of range):
 55 	>What is the input temperature? -4000
 56 	>What are the units of the input temperature (C for Celcius or F for Fahrenheit)? C
 57 	>Your input temperature is -4000C which is out of range (less than -273.15C or -416F)..
 58
 59 Bad Data case 2 (incorrect units):
 60 	>What is the input temperature? -40
 61 	>What are the units of the input temperature (C for Celcius or F for Fahrenheit)? Q
 62 	>The units you have specified are not one of C (Celcius) or F (Fahrenheit).
 63
 64 Discussion:
 65 	The program accepts any integer or decimal input temperature and a unit character which must be either C, c, F or f.
 66 	The program then prints the input temperature as well as the temperature converted into the non-input units.
 67 	Temperature range is from -273C (-415F) to any positive number.
 68 
 69*/
 70
 71#include <iostream> // Stream declarations
 72using namespace std;
 73
 74int main(void) {
 75	char input_units, output_units;
 76	float input_temp, output_temp;
 77	int error = 0;
 78
 79	// request and obtain name
 80	cout << "What is the input temperature? ";
 81	cin >> input_temp;
 82
 83	// request and obtain age
 84	cout << "What are the units of the input temperature (C for Celcius or F for Fahrenheit)? ";
 85	cin >> input_units;
 86
 87	// convert input units to upper case
 88	input_units = toupper(input_units);
 89
 90	// check input_units for acceptable response; perform appropriate conversion if acceptable and print error message if not
 91	if(input_units == 'C') {
 92		// display input
 93		cout << "Your input temperature is " << input_temp << input_units;
 94
 95		// range check input_temp
 96		if(input_temp < -273) {
 97			// disply out of range error message
 98			cout << " which is out of range (less than -273C or -416F)." << endl;
 99		}
100		else {
101			// convert from Celcius to Fahrenheit
102			output_units = 'F';
103			output_temp = (input_temp * 9.0) / (5.0 + 32.0);
104
105			// display converted output
106			cout << " which is " << output_temp << output_units << "." << endl;
107		}
108	}
109	else if(input_units == 'F') {
110		// display input
111		cout << "Your input temperature is " << input_temp << input_units;
112
113		// range check input_temp
114		if(input_temp < -416) {
115			// out of range
116			cout << " which is out of range (less than -273C or -416F)." << endl;
117		}
118		else {
119			// convert from Fahrenheit to Celcius
120			output_units = 'C';
121			output_temp = (input_temp - 32.0 * 5.0) / 9.0;
122
123			// display converted output
124			cout << " which is " << output_temp << output_units << "." << endl;
125		}
126	}
127	else {
128		// display input_unit error message
129 		cout << "The units you have specified are not one of C (Celcius) or F (Fahrenheit)" << endl;
130	}
131} ///:~