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 :)
closed account (j3Rz8vqX)
http://www.cplusplus.com/doc/tutorial/functions/

I am assuming your instructions want you to write your own function:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
double hypotenuse(int a,int b)
{
    //Insert line 17 from your illustrated post
    //Insert line 18 from your illustrated post
}

int main()
{
    double a, b, c;
    //Stuff...
    c =hypotenuse(a,b);
    cout << "The length of the hypotenuse is ";
    return 0;
}
Topic archived. No new replies allowed.