Hello Cplusplusnubblub,
I believe there may be enough of a time difference between us to make working on this long and drawn out, so I will try to get ahead.
My teacher wants us to make two global constants for the conversion multiples (these are the only global
variables that are allowed)
A pound is 453.6 grams. An ounce is 28.3495 grams. There are 1000 grams in a kilogram.
|
You have covered this well.
The proto types are in the right place, but need revised.
In main, after working with the program, these variables are better defined as type double. And you should always initialize your variables when they are defined. Not a big problem with your program, but could be. Later when you convert "pounds" and "ounces" it is better to work with doubles because using ints will loose information.
The first "cout" is OK, but I added
Whole numbers please\n
after the last "\n" to prepare for the "promptAndGetInt" function.
The next two "cout" statements will only print out the number entered not store it in the variables where they are needed. These need to be function calls that make use of what is returned.
You need two more function calls to the "convertToGrams" and "outputResults" functions both will need parameters between the () to work.
The "promptAndGetInt" function works, but not well. If you enter anything other than a whole number for "pounds" you will not get the correct number wanted and "ounces" will receive whatever is left in the input buffer. There are better ways using C++ to do this function.
My beginner's knowledge wants me to try and write something like pounds = pounds_g * ch and put that
in the conversion function and go from there but I know that is completely wrong. |
Yes that is completely wrong. First you do not want to put the answer into "pounds", but something else. This will be a temporary variable used in the function. The name should reflect that it is the result of changing pounds to grams and be a separate variable from converting ounces to grams. Both of which are added together to get total grams. Each using the appropriate constant defined at the beginning of the program. Once you have worked out the conversion for pounds and ounces add the together and return the result.
In the "outputResults" function I sent all three variables from main and used them in one "cout" statement to print the results.
That should give you something to work on for awhile.
Hope that helps,
Andy