As the other ones suggested, the value your functions returns it is available in the
main
function.
Please note you don't need the member variable
ar
, it is a dependent quantity (usually is not wise using redundant info). try
#include <iostream>
using namespace std;
class triangle
{
private:
double length, height;
public:
triangle(double l, double h):length(l), height(h){}
double area();
};
double triangle::area()
{
return (length*height)/2;
}
int main()
{
double l, h;
cout<<"enter length of the base of the right angled triangle: ";
cin >> l;
cout << endl <<"enter height the right angled triangle: ";
cin >> h;
triangle o(l,h);
cout << endl << "the area of the triangle is " << o.area() << endl;
}