Need help

I need help with this program i dont know how to do the function part here is the question. "Write a program that calculates the hypotenuse of a right triangle. the program should ask the users to enter the length of the two legs of the right triangle and the program should call a function hypotenuse() that will calculate and display the length of of the hypotenuse. NOTE: The program should include a prototype for the function hypotenuse()" i have this so far

#include <iostream>
4 #include <cmath> // Needed to use the sqrt function
5 using namespace std;
6
7 int main()
8 {
9 double a, b, c;
10
11 // Get the length of the two sides
12 cout << "Enter the length of side a: ";
13 cin >> a;
14 cout << "Enter the length of side b: ";
15 cin >> b;
16
17 // Compute and display the length of the hypotenuse
18 c = sqrt(pow(a, 2.0) + pow(b, 2.0));
19
20 cout << "The length of the hypotenuse is ";
21 cout << c << endl;
22 return 0;
23 }

all i need is the function thingy, help? nothing too sophisticated either. thanks :)
Take the part that does the calculation and prints the result and put it in a separate function.
void hypotenuse(double, double);
Then call the function from where that part was originally.
so will it look like this ?


#include <iostream>
#include <cmath>
using namespace std;


void hypotenuse(double, double);

int main()
{
double a, b, c;

cout << "Enter the length of side a: ";
cin >> a;
cout << "Enter the length of side b: ";
cin >> b;



cout << "The length of the hypotenuse is ";
cout << c << endl;
return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include <cmath>
using namespace std;

double hypotenuse(double a, double b);

int main()
{
double a, b, c;

cout << "Enter the length of side a: ";
cin >> a;
cout << "Enter the length of side b: ";
cin >> b;
c =  hypotenuse(a, b);

cout << "The length of the hypotenuse is ";
cout << c << endl;
return 0;
} 

double hypotenuse(double a, double b) {
return sqrt(pow(a, 2.0) + pow(b, 2.0));
}
All you did was remove the calculation and add the prototype I gave you. Bingocat4 showed you a way to do it and you should be able to figure out how to do it the right way from that.
Topic archived. No new replies allowed.