For some reason when I compile my code the hypotenuse returns to just 0 and it returns an integer and not a double and was wanting to know if anyone had any suggestions........

``````#include <iostream>
#include <cmath>
using namespace std;
double Calculate_Hypotenuse(int length_one, int length_two);

int main()
{
int length_one, length_two;
double hypotenuse = 0.0;

cout << "Programmed by Jim Johnson";
cout << endl << endl << "Type a negative number for side 1 to exit the program";
cout << endl;

do
{

cout << "Enter the length of the side 1 in inches: ";
cin >> length_one;

if (length_one >= 0)
{

cout << "Enter the length of the side 2 in inches: ";
cin >> length_two;

cout << endl << endl << "Triangle: Side 1: " << length_one << " inches";
cout << endl <<"\t  Side 2: " << length_two << " inches";

Calculate_Hypotenuse(length_one, length_two);
cout << endl <<"Hypotenuse: " << hypotenuse << " inches";
cout << endl << endl;

}

cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);

} while (length_one >=0);
return 0;
}

double Calculate_Hypotenuse(int length_one, int length_two)
{
double area;
double hypotenuse;

area = pow(length_one,2.0) + pow(length_two,2.0);
hypotenuse = sqrt(area);

return hypotenuse;
}``````
3
Contributors
2
Replies
4
Views
9 Years
Discussion Span
Last Post by gkbush
``````// ...
if (length_one >= 0)
{

cout << "Enter the length of the side 2 in inches: ";
cin >> length_two;

cout << endl << endl << "Triangle: Side 1: " << length_one << " inches";
cout << endl <<"\t  Side 2: " << length_two << " inches";

hypotenuse = Calculate_Hypotenuse(length_one, length_two);
cout << endl <<"Hypotenuse: " << hypotenuse << " inches";
cout << endl << endl;

}
// ...``````

I believe you need to cast the integers to doubles to return a double.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.