Help Please!!!! im stuck :/

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.)



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include <iostream>
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." <<endl;
	}

}

int main()
{
	double choice(1), value(0), lengths(0), weights(0), choice_2(1), value_2(0), metric(0), us(0), feet(0), inches(0), final_m(0), final_cm(0);

	introduction();

	while (choice != 0 && choice_2 != 0)
	{
		get_input(choice);
		get_output(choice, lengths, weights, value, choice_2, value_2, metric, us, feet, inches);
	}
	input_number(feet, inches);
	do_conversion(feet, inches, final_m, final_cm);
	output_number(final_m, final_cm);
	return 0;
}
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?

1
2
3
4
5
6
7
8
9
10
11
12
13
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:

1
2
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.