How can I transfer the user input from function to function

I cant seem to get the program to calculate the hypotenuse. It prints 0.00 everytime. I think it's because it has no clue about the user's input.

(I'm aware is an easier way to make a hypotenuse calculator but we're studying fuctions)



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
 #include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
using namespace std;


void getLegs (double&, double &);
double calcHypotenuse (double, double);

int main()
{

double length1;
double length2;


cout<<endl;
cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
cout<< " Welcome to the Hypotenuse Calculator program!\n";
cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
cout<<endl;


getLegs (length1, length2);
 

calcHypotenuse (length1,length2);


return 0;

}



// Function that prompts for and obtains the lengths of the legs of a right 
// triangle from the user and 'returns' their values by reference 
void getLegs(double &, double &) 
{ 
double legOne;
double legTwo;
cout <<"Please enter the length of side 1: ";   
cin>>legOne;
cout<<"Please enter the length of side 2: "; 
cin>>legTwo;
} 
 
// Function that computes and returns the hypotenuse of a right triangle, 
// given the lengths of the legs 

double calcHypotenuse(double legOne, double legTwo) 
{ 
double hypotenuse;
hypotenuse = sqrt((pow(legOne, 2)) + (pow(legTwo, 2)));
cout<<setprecision(2)<<fixed<<showpoint;

cout<<"The hypotenuse of your triangle is " << hypotenuse<<endl;

return hypotenuse;


}
1
2
3
4
void getLegs(double &legOne, double &legTwo) 
{
// and get rid of the declarations of legOne and legTwo inside the function!
}

wow easy fix, thank you!
Perhaps this http://www.cplusplus.com/doc/tutorial/functions/ explains some details of functions that your course material was not clear about?
thank you ^^^
Topic archived. No new replies allowed.