Trouble with my functions

Here's the code I'm working on. I've having problems with the last function; if you run the program the last function prints to screen all zeros. I'm sure my parameters for final output are wrong, but everything I change just seems to make more problems. Help anyone?
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

#include <string> 
#include <iomanip>
#include <fstream> 
#include <iostream>

using namespace std;

void introduction();
void inputValue(double &feetValue, double &inchValue);
double calculation(double &coninch, double &confeet);
void finaloutput(double &meterft, double &meterin, double &totalmeter);


double meterft, meterin, totalmeter; 
	double feetValue, inchValue;


int main()
{
	
	introduction();
	
	inputValue(feetValue, inchValue);
	calculation(meterft, meterin );
	finaloutput(meterft, meterin, totalmeter);
	
	
} 

void introduction()
{
	cout << "This program will accept an input of feet and/or inches. From there the program will convert the value into meters." << endl;
}

void inputValue(double &feetvalue, double &inchValue )
{
	
	cout << "Please enter the number of feet." << endl; 
	cin >> feetValue ; 
	cout << "Please enter the number of inches." << endl; 
	cin >> inchValue ;
	cout << "You've entered: " << feetValue << " feet." << endl; 
	cout << "You've entered: " << inchValue << " inches." << endl; 
	
}

double calculation(double &coninch, double &confeet)
{
	double inch2feet = 12 ;
	double feet2meter = .3048 ;
	double meterft, meterin; 
	meterft = (feetValue * feet2meter) ; 
	meterin = (feet2meter *(inchValue / inch2feet)); 
	double totalmeter = meterft + meterin ;
	cout << meterft << " " << meterin << " " << totalmeter << endl; 
	return totalmeter; 
}

void finaloutput(double &meterft, double &meterin, double &totalmeter)
{
	cout << "So these are your final values for your inputs in meters." << endl;
	cout << "For feet entered: " << meterft << endl;
	cout << "For inches entered: " << meterin << endl;
	cout << "Total of both: " << totalmeter << endl; 
} 

Take a look at and ponder line 25, and line 52.
The error in the function

1
2
3
4
5
6
7
8
9
10
11
double calculation(double &coninch, double &confeet)
{
	double inch2feet = 12 ;
	double feet2meter = .3048 ;
	double meterft, meterin; 
	meterft = (feetValue * feet2meter) ; 
	meterin = (feet2meter *(inchValue / inch2feet)); 
	double totalmeter = meterft + meterin ;
	cout << meterft << " " << meterin << " " << totalmeter << endl; 
	return totalmeter; 
}


Instead of to do calculations with variables coninch and confeet you are doing calculations with local variables

double meterft, meterin;

which will be destroyed after exiting from the function.
Last edited on
Well I was trying to avoid just straight up solving it but.. xD Might as well also point out that nothing is being done with the "calculation" function's return value.
Wow you guys are fast, thanks for insight.
Topic archived. No new replies allowed.