Hi I'm new to this site. You guys seem helpful though. I am taking a beginners class and this stuff doesn't click with me too well. I followed my logic step by step with commenting out and outputting everything and everything works well except in my final function when I output, everything becomes 0. Any help would be greatly appreciated.
/*
File: convert2metric.cpp
Created by: ???
Creation Date: ???
Synopsis:
This program reads in a length yards, feet and inches,
and converts to meters and centimeters.
*/
int read_us_length(int & yards, int & feet, int & inches);
// FUNCTION PROTOTYPE FOR convert2inches
int convert2inches(int yards, int feet, int inches);
// FUNCTION PROTOTYPE FOR convert2metric
int convert2metric(int & total_inches, int meters, int centimeters);
// FUNCTION PROTOTYPE FOR write_metric_length
void write_metric_length(int meters, int centimetersB);
int main()
{
int yards, feet, inches; // length in yards, feet and inches
int total_inches; // total length in inches
int meters, centimeters; // length in meters and centimeters
I think your main problem is with the convert2metric() function. Pass meters and centimeters by reference so the values get changed by the function. Also, work with just centimeters in the function, not the local centimetersB.
Another issue is that two of the functions are declared as returning an integer value but there are no return statements in them. Are you getting no warnings about this? These functions should have a void return type though as no use is made of any returned value in main() anyways.
EDIT: I continue to be amazed at the frequency of the ninja'd phenomenon!
3-1/2 hours with no replies then 2 in the same minute. Wow!
There is no return statement in the convert2metric function, otherwise the parameters meters & centimeters are not passed as references - which is what you really need as returning an int isn't sufficient.
Can you please always use code tags - select you code then press the <> button on the right under the format menu.
This helps us because it shows line numbers & preserves formatting - making it easier to read.