A few comments:
1) You should handle all of the user input directly in main and then pass values to the functions (rather than call the functions with no arguments and do the input inside as you have done).
2) Rather than have a conversion from each type to every other one (imagine how complicated this would get if there were 10 types instead of 3!), I would always convert to a "common" format (say always to decimal). Then you can have a single function for each type to convert from the common type. You will then have ~2N functions vs ~N^2 (where N is the number of types)
3) Use descriptive variable and function names! c_f_fraction_1 is not obvious to a first time reader of the code.
Good luck,
David
daviddoria
Posting Virtuoso
1,996 posts since Feb 2008
Reputation Points: 437
Solved Threads: 204
1) Instead of
if (convert_code == "f")
{
c_f_fraction();
}
you'd want to do:
main()
{
if (convert_code == "f")
{
std::cout << "\nPlease input the numerator of the fraction you wish to convert.<#/help> ";
std::cin >> numerator;
std::cout << "\nPlease input the denominator of the fraction you wish to convert.<#/help> ";
std::cin >> denominator;
c_f_fraction(numerator, denominator);
}
}
double c_f_fraction(double numerator, double denominator)
{
// your logic here (something like return numerator/denominator;
}
See what I mean? This way the function is much more reusable (if you read numbers from a file, or generated them manually, you can still convert them (rather than relying on user input to happen in every instance).
3) The idea is "documentation by good code writing". The problem is that you have to assume programmers will not keep the documentation up to date (that is, they will change the code but forget to update the documentation). So,you have to train them to write the code in such a way that it is "self documenting". The use of intelligible variable names is a good start.
daviddoria
Posting Virtuoso
1,996 posts since Feb 2008
Reputation Points: 437
Solved Threads: 204