Convert2

# Convert2 - cout << "Type a C, F, or Q; then...

This preview shows pages 1–2. Sign up to view the full content.

// file: .cpp // author: j. dzuback // modified: // date: / /* ********************************************************** Program Convert converts a temperature from Fahrenheit to Celsius or a temperature from Celsius to Fahrenheit depending on whether the user enters an F or a C. ********************************************************** */ #include <iostream> using namespace std; u int ConvertedTemp(int tempIn, char letter); void Error(); char letter; void menu(); v int main () { menu(); int tempIn; // Temperature to be converted / cout << "Type a C, F, or Q; then press return." << endl; cout << "Make your selection: "; cin >> letter; c while (letter != 'Q') { cout << " Type an integer number, and press return: "; cin >> tempIn; if (letter == 'F') cout << "Fahrenheit to Celsius" << endl; else e cout << "Celsius to Fahrenheit: " << endl; cout << "Temperature to convert: " << tempIn << endl; cout << "Converted temperature: " << ConvertedTemp(tempIn, letter) << endl << endl;

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: cout << "Type a C, F, or Q; then press return: "; cin >> letter; } return 0; } void menu () { cout << "Input Menu" << endl << endl; cout << "F: Convert from Fahrenheit to Celsius" << endl; cout << "C: Convert from Celsius to Fahrenheit" << endl; cout << "Q: Quit" << endl; return; } /* ***************************************************** Function converts temperature from celsius to fahenheit or from fahrenheit to celsius based on code supplied Pre conditions: an interger temperature a letter code, 'C' or 'F'. Post condition: interger temperature will be converted from one scale to the other, based on code. ***************************************************** */ int ConvertedTemp(int tempIn, char letter) { if (letter == 'C') return (9 * tempIn / 5) + 32; else return 5 * (tempIn - 32) / 9; } void Error() { if (letter=='C' || letter =='F' || letter=='Q') false; else true; }...
View Full Document

## This note was uploaded on 02/08/2011 for the course CSC 101 taught by Professor Joedzuback during the Spring '11 term at Union County.

### Page1 / 2

Convert2 - cout << "Type a C, F, or Q; then...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online