I have this program
Define a function hypotenuse that calculates the length of the hypotenuse of a right triangle when the other two sides are given (22__hsideasideb=+). Use this function in a program to determine the length of the hypotenuse for each of the triangles shown below. The function should take two double arguments and return the hypotenuse as a double. Hint: Use cmath.h and the functions sqrt(double x), and pow(double x, int y).
Triangle Side 1 Side 2

1          3.0     4.0
2          5.0     12.0
3          8.0      15.0
and i write this,not working to print the result
#include "stdafx.h"
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

double Hypotenuse(double sideA, double sideB);
/*********************************************/
double Hypotenuse(double sideA, double sideB)
{
double hypotenuse = 0.0;
hypotenuse= sqrt((sideA*sideA)+(sideB*sideB));
return hypotenuse;
}

int _tmain(int argc, _TCHAR* argv[])
{
double sideA=0.0;  
double sideB=0.0;  
double hypotenuse= 0.0;

    int i;
 for(i=1;i<=3;i++){
    cout<<"Enter the first side for the triangle: ";
 cin>>sideA;

 cout<<"Enter the second side for the triangle: ";
 cin>>sideB;
 cout<<endl;

hypotenuse = Hypotenuse(sideA, sideB);
 }

cout<<"Trinagle "<<"  "<<"Side 1"<<"  "<<"Side 2"<<"  "<<"Hypotenuse"<<endl;
cout<<"-------------------------------------"<<endl;
cout<<endl;

for(i=1;i<=3;i++)
  {
  cout<<setw(5)<<i <<setw(5)<<sideA<<setw(5)<<sideB<<setw(5)<<hypotenuse<<endl; 
     }

system("pause");
return 0;
}

Your first for loop is calculating lots of results, and throwing them away. You should calculate a results, and then output it, and then move on to the next result.

first i'll post the corrected one.. then i'll talk about your mistakes :)

#include <iostream>
#include "windows.h"
#include <cmath>
#include <iomanip>
using namespace std;
double Hypotenuse(double sideA, double sideB);
/*********************************************/
double Hypotenuse(double sideA, double sideB)
{
double hypotenuse = 0.0;
hypotenuse= sqrt((sideA*sideA)+(sideB*sideB));
return hypotenuse;
}
int main()
{
double sideA=0.0;
double sideB=0.0;
double hypotenuse= 0.0;
    int i;
 for(i=1;i<=3;i++){
    cout<<"Enter the first side for the triangle: ";
 cin>>sideA;
 cout<<"Enter the second side for the triangle: ";
 cin>>sideB;
 cout<<endl;
hypotenuse = Hypotenuse(sideA, sideB);

 }
cout<<"Trinagle "<<"  "<<"Side 1"<<"  "<<"Side 2"<<"  "<<"Hypotenuse"<<endl;
cout<<"-------------------------------------"<<endl;
cout<<endl;
for(i=1;i<=3;i++)
  {
  cout<<setw(7)<<i <<setw(7)<<sideA<<setw(7)<<sideB<<setw(7)<<hypotenuse<<endl;
     }
system ("pause");
return 0;
}
  1. you didn't include windows.h that's why the system pause gave an error.
  2. you includede some other things that I think wasn't needed..
  3. do your comparison... :D
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.