5 Replies - 9329 Views - Last Post: 14 November 2012 - 07:42 PM Rate Topic: -----

#1 gummybear  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 26-August 09

C++ function right triangle using two sides

Posted 26 August 2009 - 05:47 AM

write a function named right triangle ( ) that accepts the lengths of two sides of a right triangle as the parameters a and b respectively determine the hypotenuse C, and use pythagorean theory
#include <iostream>
using namespace std;

void char  RTriangle ( a, b );
int a, b,c, side1, side 2;

int main ( )
{
	 cout<< "PLease enter side1:" <<endl;
	 cin >>side1;
	 cout <<"Please enter side 2:" <<endl;
	 cin >> side2;
	 c^2= a^2 + b^2.
	{
		cout<<"The Hypotenuse of of the right triangle is:"<<c^2= a^2 +  b^2.<<endl;
}

return 0;

}



***added code tags - jjsaw5***

This post has been edited by jjsaw5: 26 August 2009 - 06:04 AM


Is This A Good Question/Topic? 0
  • +

Replies To: C++ function right triangle using two sides

#2 jjsaw5  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 92
  • View blog
  • Posts: 3,063
  • Joined: 04-January 08

Re: C++ function right triangle using two sides

Posted 26 August 2009 - 06:03 AM

What seems to be your issue?


:code:
Was This Post Helpful? 0
  • +
  • -

#3 DaneAU  Icon User is offline

  • Great::Southern::Land
  • member icon

Reputation: 286
  • View blog
  • Posts: 1,620
  • Joined: 15-May 08

Re: C++ function right triangle using two sides

Posted 26 August 2009 - 06:29 AM

You need a function that will return the square root of a^2 + b^2 - which in turn will return the length of the hypotenuse.

Eg
double rTriangle (double a,  double b )
{
     double hypotenuse;

     // do the maths here using a & b then return it

     return hypotenuse;
}


This post has been edited by bbq: 26 August 2009 - 06:29 AM

Was This Post Helpful? 0
  • +
  • -

#4 Cherish.r  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 14-November 12

Re: C++ function right triangle using two sides

Posted 14 November 2012 - 07:11 PM

Hey it didnt work :(

#include <iostream>
using namespace std;

void double RTriangle ( double a , double b );
int a, b, c, side1, side2;

int main ( )
{
cout<< "PLease enter the length of side1:" << endl;
cin >> side1;
cout <<"Please enter the length of side 2:" << endl;
cin >> side2;
c^2= a^2 + b^2


}
{
cout<<"The Hypotenuse of of the right triangle is:"<<c^2= a^2 + b^2.<<endl;
}

return 0;

}
Was This Post Helpful? 0
  • +
  • -

#5 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1852
  • View blog
  • Posts: 6,661
  • Joined: 19-February 09

Re: C++ function right triangle using two sides

Posted 14 November 2012 - 07:39 PM

This is not proper code.

c^2= a^2 + b^2




The pow function can be used to calculate powers, but a*a is just as easy.

hypotenuse_squared = (a * a) + (b * B)/>;




The sqrt function can be used to calculate the square root.

hypotenuse = sqrt(hypotenuse_squared);




The sqrt and pow function are in the C++ cmath header.

cmath
Was This Post Helpful? 0
  • +
  • -

#6 Adak  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 331
  • View blog
  • Posts: 1,168
  • Joined: 01-April 11

Re: C++ function right triangle using two sides

Posted 14 November 2012 - 07:42 PM

Cherish.r: Always always, put [ code] tags around any code you post. The icon is in the editor near the center of the top icon bar.

Without those, your code becomes almost impossible to study.

This:
c^2= a^2 + b^2.


is OK for math, but in C you need to either use pow() (part of your compiler's math header file, which you must include), or multiply it yourself.

This post has been edited by Adak: 14 November 2012 - 07:45 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1