Hello,
I am new to C++ programming. I am requesting help to understand
how to use a nested if/else statement to finish my project.
I don't expect you to write my program for me, but I would appreciate
any pointers you can give me. The program I have written so far has no
errors, but it is out of sequence. I just wrote what I understood.
I am learning how to use function prototypes. I am having difficulty
understanding how to tie everything back into main() function.
Here is the code I have so far. Please help me on this project.
Thanks.
// Author: Emily Gibson
// Class: CS300 Programming in C++, Fall 2005
// Section: 02
// Program: Lab_6_EmilyGibson
// Version: ANSI/ISO C++
// Date: December 2, 2005
//The purpose of this program is to provide the user with a means to perform
//conversion operations on units of measure and vice-versa. It also provides
//the user with a termination option if the user prefers to quit the program.
//This program will be accomplished using a multi-function program instead of
//using a strictly int main () format.
#include <iostream>
using namespace std;
//function prototypes
char ConverMenu ();
double Fht2Cls(double);
double Cls2Fht(double);
double Gln2Lts(double);
double Lts2Gln(double);
double Mls2Klm(double);
double Klm2Mls(double);
int main ()
{
//Declare and initialize variables.
char operation = ' ';
//Terminate
return 0;
}//end function main()
//function definitions
char ConverMenu()
{
//Declare variables and initialize
char choice = ' ';
//Display the user menu. The menu will be displayed using a do while statement because
//by doing so the program menu and results will be guaranteed to display at least once.
//This menu will use a clear screen operation, display the menu introduction message,
//and it is designed to loop until a valid response from the user is received by the
//program. The while portion of the do while loop tells the program to continue looping
// when the user input is not equal to a valid menu option.
do
{
system ("cls");
cout << "The purpose of this program is to provide the user with a means\n";
cout << "to convert various units of measure to their metric counterpart\n";
cout << "and vice-versa.\n";
cout << "\nPlease select a conversion option from the menu below,\n";
cout << "or if you prefer, you may choose to Quit the program.\n\n";
cout << "'0' - Exit the program \n";
cout << "'1' - Convert degrees Fahrenheit to degrees Celsius\n";
cout << "'2' - Convert degrees Celsius to degrees Fahrenheit\n";
cout << "'3' - Convert U.S. gallons to liters\n";
cout << "'4' - Convert liters to U.S. gallons\n";
cout << "'5' - Convert statute miles to kilometers\n";
cout << "'6' - Convert kilometers to statute miles\n";
cout << "\nPlease enter your conversion menu choice now: ";
cin >> choice;
cin.clear();
}
while ((choice != '0') && (choice != '1') && (choice != '2') && (choice != '3')
&& (choice != '4') && (choice != '5') && (choice != '6'));
return choice;
}//end function ConverMenu()
//function Fht2Cls.
double Fht2Cls(double Fht)
{
//Declare and initialize variables.
double Cls = 0.0;
Cls = (5/9 * (Fht - 32));
return Cls;
}//end function Fht_to_Cls
//function Cls_to_Fht.
double Cls2Fht(double Cls)
{
//Declare and initialize variables.
double Fht = 0.0;
Fht = (9/5 * (Cls + 32));
return Fht;
}//end function Cls_to_Fht
//function Gln2Lts.
double Gln2Lts(double Gln)
{
//Declare and initialize variables.
double Lts = 0.0;
Lts = (Gln * 3.785);
return Lts;
}//end function Gln2Lts.
//function Lts2Gln.
double Lts2Gln(double Lts)
{
//Declare and initialize variables
double Gln = 0.0;
Gln = (Lts / 3.785);
return Gln;
}//end function Gln2Lts.
//function Mls2Klm.
double Mls2Klm(double Mls)
{
//Declare and initialize variables.
double Klm = 0.0;
Klm = (Mls * 1.609344);
return Klm;
}//end function Mls2Klm.
//function Klm2Mls.
double Klm2Mls(double Klm)
{
//Declare and initialize variables.
double Mls = 0.0;
Mls = (Klm / 1.609344);
return Mls;
}//end function Klm2Mls.