#include <iostream> #include <iomanip> using namespace std; void displayMenu (void); char getMenuSelection (void); void getStartEndAndIncrement(double& start, int& end, int& increment); void CtoF(double& celsius, double& F,int& increment,double& start); void displayCtoFTable(double& start, int& end, int& increment,double& F); int end, increment; char choice; double start; double celsius; double F; int main() { displayMenu (); getMenuSelection (); getStartEndAndIncrement (start,end,increment); if (choice=='C'){ CtoF(celsius,F,increment,start); displayCtoFTable(start,end,increment,F);} cin.ignore(2); } void displayMenu () { cout << "Celsius and Fahrenheit Temperation Converter\n" << endl; cout << "Please choose from the following options\n" << endl; cout << "C: Convert from CELSIUS to FAHRENHEIT" << endl; cout << "F: Convert from FAHRENHEIT to CELSIUS" << endl; cout << "Q: Quit" << endl; } char getMenuSelection () { cout << "\nEnter your choice: "; cin >> choice; switch (choice) { case 'C': cout <<"You have choosen a CELSIUS to FAHRENHEIT conversion"<<endl; return choice; break; case 'F': cout <<"You have choosen a FAHRENHEIT to CELSIUS"<<endl; return choice; break; case 'Q': cout <<"Press ENTER to terminate program"<<endl; cin.ignore(2); return choice; } do { cout << "Sorry, invalid choice\n"<<endl; displayMenu (); getMenuSelection (); break; } while (choice != 'C' && choice != 'F' && choice != 'Q'); } void getStartEndAndIncrement(double& start, int& end, int& increment) { cout << "Enter start:"; cin >> start; cout << "Enter End:"; cin >> end; cout << "Enter Increment:"; cin >> increment; } void CtoF(double& celsius, double& F,int& increment,double&start) { celsius = start; F = (9.0 * celsius/5.0) + 32.0; cout.precision(3); } void displayCtoFTable(double& start, int& end, int& increment,double&F) { cout << "==============================================" << endl; cout << "|********************************************|" << endl; cout << "|*********** Celcius to Farenheit ***********|" << endl; cout << "|********************************************|" << endl; cout << "---------------------------------------------" << endl; cout << "| Start C || Ending C | Increment |" << endl; cout << "============================================= " << endl; cout << "| Celsius || Farenheit |" << endl; cout << "==============================================" << endl; for (celsius = start; celsius <= end; celsius+=increment){ cout <<"|"<< setw(10)<< celsius<<setw(11)<<"||" <<setw(13)<<F++<<setw(11)<<"|"<<"\n";} cout << "==============================================" << endl; cout << "==============================================" << endl; } |
<<setw(13)<<F++<<setw(11)<<"|"<<"\n";} |
|
|
|
|