Okay so heres what i have to do --->Program 4c: Second iteration

Design and implement the stub functions length_to_metric, length_to_us, weight_to_metric, and weight_to_us from Program 4b. The function length_to_metric should read the length in feet and inches and output the equivalent length in meters and centimeters. To accomplish this task, length_to_metric should use three additional functions: one to input the values, one to do the conversion, and one to output the results. Similarly, the function length_to_us should read the length in meters and centimeters and output the equivalent length in feet and inches. To accomplish this task, length_to_us should use three additional functions: one to input the values, one to do the conversion, and one to output the results. (Note: there are 0.3048 meters in a foot, 12 inches in a foot, and 100 centimeters in a meter.)
The function weight_to_metric should read the weight in pounds and ounces and output the equivalent length in kilograms and grams. To accomplish this task, weight_to_metric should use three additional functions: one to input the values, one to do the conversion, and one to output the results. Similarly, the function weight_to_us should read the weight in kilograms and grams and output the equivalent weight in pounds and ounces. To accomplish this task, weight_to_us should use three additional functions: one to input the values, one to do the conversion, and one to output the results. (Note: there are 2.2046 pounds in a kilogram, 1000 grams in a kilogram, and 16 ounces in a pound.)

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139`` ``````#include using namespace std; double input_number(int feet, double inches) { cout << "please enter the number of feet" << endl; cin >> feet; cout << "please enter the number of inches" << endl; cin >> inches; return 1; } void do_conversion(int feet, double inches, double final_m, double final_cm) { final_m = feet * .3048; final_cm = inches * 2.54; } double output_number(double final_m, double final_cm) { cout << "You values conver to:" << endl; cout << final_m << "meters and" << final_cm << "cm." << endl; cout << endl; return 1; } double convert_lengths(double choice, double value, double lengths) { return 1; } double convert_weights(double choice, double value, double weights) { return 2; } double length_to_metric(double choice_2, double value_2, double metric, int feet, double inches) { cout << "You have choosen to convert ft/in. to m/cm." << endl; metric = input_number(feet, inches); return 1; } double length_to_us(double choice_2, double value_2, double us) { cout << "You have choosen to convert m/cm to ft/in.." << endl; return 2; } double weight_to_metric(double choice_2, double value_2, double metric) { cout << "You have choosen to convert lbs/oz. to kg/g." << endl; return 1; } double weight_to_us(double choice_2, double value_2, double metric) { cout << "You have choosen to convert kg/g to lbs/oz." << endl; return 2; } void introduction() { cout << "This program converts lengths and weights." << endl; cout << "Press 1 to convert lengths." << endl; cout << "Press 2 to convert weights." << endl; cout << "Press 0 to end the program." << endl; } void get_input(double& choice) { cout << endl; cout << "What would you like to convert (length or weight)? Please enter your choice: "; cin >> choice; } void get_output(double choice, double lengths, double weights, double& value, double choice_2, double value_2, double metric, double us, int feet, double inches) { if(choice == 1) { value = convert_lengths(choice, value, lengths); cout << "You choose lenghts." << endl; cout << endl; cout << "Would you like to convert ft./in. to m/cm? If so press 1" << endl; cout << "If you would like to convert m/cm to ft./in.? if so press 2." << endl; cout << "If you would like to stop converting length measurments press 0." << endl; cout << "Enter:"; cin >> choice_2; if(choice_2 == 1) { cout << "You pressed 1" << endl; value_2 = length_to_metric(choice_2, value_2, metric, feet, inches); } if(choice_2 == 2) { cout << "You pressed 2" << endl; value_2 = length_to_us(choice_2, value_2, metric); } } if(choice == 2) { value = convert_weights(choice, value, weights); cout << "You choose weights." << endl; cout << endl; cout << "Would you like to convert lbs/oz. to kg/g? If so press 1" << endl; cout << "If you would like to convert kg/g to g/kg? if so press 2." << endl; cout << "If you would like to stop converting weight measurments press 0." << endl; cout << "Enter: "; cin >> choice_2; if(choice_2 == 1) { cout << "You pressed 1" << endl; value_2 = weight_to_metric(choice_2, value_2, metric); } if(choice_2 == 2) { cout << "You pressed 2" << endl; value_2 = weight_to_us(choice_2, value_2, us); } } if(choice == 0) { cout << "Program Terminated." <
Really nice code. May be lines are a little bit long, but...

Ok, surely you wouldn't get a price for the most beautiful program. So please, what's your question please?
i was trying to test my code more specifically the code bellow. i was plugging in values for feet and inches put i can not get my program to give me the new values for meters and cm.....what must i do to get this code to work?

 ``12345678910111213`` ``````void do_conversion(int feet, double inches, double final_m, double final_cm) { final_m = feet * .3048; final_cm = inches * 2.54; } double output_number(double final_m, double final_cm) { cout << "You values conver to:" << endl; cout << final_m << "meters and" << final_cm << "cm." << endl; cout << endl; return 1; }``````
In my own view of the above code:
final_m and final_cm in do_conversion() is local to do_conversion and since no value is returned to the caller from the sender, how do you think another function would be able to call a local variable from another function when its not global?! If final_m and final_cm were sent by reference, then yes, the value would appear.
Hi, simply add '&" before the final_m and final_cm:

 ``12`` ``````void do_conversion(int feet, double inches, double& final_m, double& final_cm) {...}``````

Hope this helps :))
thank you osgwsy!!! i pluged it in.....but the program will still not given me my new values for meters and cm.....i cant figure out why!!! :/
Hi bobbyray, besides the one I mentioned earlier, I think there are several errors.

For Line 126 and Line 130:
To what I see, you set choice = 0 to end the program, but because of line 130, if I enter choice = 1 or 2, it will be in this while loop and not getting out. So it will not do the any conversion.

For Line 3:
You will need to put & in front of feet and inches.

Then again, for your variable 'feet', sometime you declare it as int (Line 3, 11...), other time as double. I would suggest you change everything to double.

*I think you code is abit too long. You might want to go through and see again.

It is a really easy question, i think what Matri X and osgwsy said should fix ur problem already, don't know what happened to ur code, after u added the address operator(&), it definitely would change the values of final_m and final_cm, u could test this function only. There should be problem in the code somewhere else. Use debugger or print out every single input and output if necessary. Good luck mate~
You need to return value. <- period
Topic archived. No new replies allowed.