# function to compute right triangle data

• 06-17-2007
BJtoVisualcC++
function to compute right triangle data
I am stuck on this problem of computing the area and perimeter of a right triangle Can someone help please to tell me where I have gone wrong[

CODE][/CODE]

// Compute area and perimeter of right triangle
#include <iostream>
#include <cctype>
#include <cmath>
using namespace std;

double right_tri_area (double base, double height);
// Area formule

double right_tri_perimeter (double a, double b, double h);
// Perimeter formula

int main()
{
double base, height,
a, b, h, perimeter,
area;
cout << "Enter base and height of the triangle: ";
cin >> base >> height;
area = right_tri_area(base,height);
cout << "Area = " << area << endl;
cout << "Enter the two sides'lengths of sides anhd base of the triangle: ";
cin >> a >> b >> h;
cout << "Perimeter = " << right_tri_perimeter(a, b, h) << endl;
system("pause");
return 0;
}

double right_tri_area (int base, int height)
{ right_tri_area = (base * height)/2; // system("pause");
return 0; }

double right_tri_perimeter (int a, int b, int h)
{ right_tri_perimeter = (a + b + h);
// system("pause");
return 0; }

• 06-17-2007
mike_g
Hey dude, just to let you know the [/code] tag goes after your code ;)

Try this:
Code:

```// Compute area and perimeter of right triangle #include <iostream> #include <cctype> #include <cmath> using namespace std; double right_tri_area (double base, double height) { return (base * height)/2; } // Area formule double right_tri_perimeter (double a, double b, double h) { return (a + b + h); } // Perimeter formula int main() { double base, height, a, b, h, perimeter, area; cout << "Enter base and height of the triangle: "; cin >> base >> height; area = right_tri_area(base,height); cout << "Area = " << area << endl; cout << "Enter the two sides'lengths of sides anhd base of the triangle: "; cin >> a >> b >> h; cout << "Perimeter = " << right_tri_perimeter(a, b, h) << endl; system("pause"); return 0; }```
Code:

```double right_tri_area (int base, int height) { right_tri_area = (base * height)/2; // system("pause"); return 0; } double right_tri_perimeter (int a, int b, int h) { right_tri_perimeter = (a + b + h); // system("pause"); return 0; }```
You don't set the function value, you want to be returning a value from the function instead. Apart from that your program was fine, but you may want to get int the habit of indenting. [/edit]
• 06-17-2007
BJtoVisualcC++
Thank you thank you and thank you Can you help with the other posting about changing it to an input file--let me post it new
• 06-17-2007
mike_g
No need to post it again, I'll have a look for it.
• 06-17-2007
BJtoVisualcC++
There were some changes so I redid it under classify number to file
• 06-17-2007
BJtoVisualcC++
Your right about the indenting I have not made the program my file because of no documentation either