Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I would like some help with this program because I am lost . i put the errors af

ID: 3654702 • Letter: I

Question

I would like some help with this program because I am lost . i put the errors after the program ./* This program reads in a length yards, feet and inches, and converts to meters and centimeters. */ #include #include #include using namespace std; // FUNCTION PROTOTYPE FOR read_us_length 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 int write_metric_length(int meters,int centimeters); ------------------------------------------------------------------------------------MAIN CANNOT BE ALTERED--------------------------------------- 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 read_us_length(yards, feet, inches); total_inches = convert2inches(yards, feet, inches); convert2metric(total_inches, meters, centimeters); write_metric_length(meters, centimeters); return 0; } // DEFINE FUNCTION read_us_length HERE: int read_us_length(int yards,int feet,int inches) { cout<<"FOR READING LENGTHS: "; cout<<"Enter yards: "; cin>>yards; cout<<"Enter feet: "; cin>>feet; cout<<"Enter inches: "; cin>>inches; if (yards<0) { cerr<<"Yards cannot be negative!"<<endl; } else if (feet<0) { cerr<<"feet cannot be negative!"<<endl; } else if (inches<0) { cerr<<"inches cannot be negative!"<<endl; return read_us_length; } } // DEFINE FUNCTION convert2inches HERE: int convert2inches(int yards,int feet,int inches) { int total_inches; total_inches=yards * 36 + feet * 12 + inches; return convert2inches; } // DEFINE FUNCTION convert2metric HERE int convert2metric(int total_inches,int meters,int centimeters) { centimeters = total_inches*2.54; meters = centimeters/100; return convert2metric; } // DEFINE FUNCTION write_metric_length HERE: int write_metric_length(int meters,int centimeters) { cout<<"Number of Centimeters: "<<centimeters<<endl; return centimeters; cout<<"Number of Meters: "<<meters<<endl; return meters; cout<<"FOR centimeters (B): "<<convert2metric<<endl; } ----------------------------------------------------ERRORS-------------------------------------------------------------------------------------------- g++ convert2metric.cpp convert2metric.cpp: In function

Explanation / Answer

/* You seem to need to work on returning variables. Usually, functions can take in values three ways: by Value (like passing a copy of the value), by Reference (passing the address of that variable and any change to the value by the function would reflect on the value passed in) , or by passing an Array (similar to by reference). A function naturally can only return one value, but if you pass by reference, you can manipulate several variables at once with the function. What needs to be returned by a function is not the function's name, but the variable/expression that the caller is looking for. Also, when a function 'return' control to the caller, it loses control and thus, is terminated. */ /* This program reads in a length yards, feet and inches, and converts to meters and centimeters. */ #include //#include //#include using namespace std; // FUNCTION PROTOTYPE FOR read_us_length void 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 void convert2metric(int total_inches,int &meters,int ¢imeters); //changed to void // FUNCTION PROTOTYPE FOR write_metric_length void write_metric_length(int meters,int centimeters);//changed to void //------------------------------------------------------------------------------------MAIN CANNOT BE ALTERED--------------------------------------- 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 read_us_length(yards, feet, inches); total_inches = convert2inches(yards, feet, inches); convert2metric(total_inches, meters, centimeters); write_metric_length(meters, centimeters); return 0; } // DEFINE FUNCTION read_us_length HERE: void read_us_length(int &yards,int &feet,int &inches) { //a misplaced } and returning wrong variable cout