Im doing a question that asked to include a header of area function to find the area of the triangle if the input is valid.
Here are my codes for the header and also the main function.
Why i get the address or some weird code for the area?
I can conclude that you are using MS VC++ which incorrectly ouputs a function address when the name of a function is used in operator << instead of to output bool value true.:)
area - is not a call of a function. Function call has special syntax when after the function name alsit of argunebts enclosed in parentheses follows.
I to am a beginner at c++ but I found ths problem an interesting practice for me. It is my understanding that the area of a triangle is (base x height) / 2. So, I wrote a function that perfoms this. Here is the code.
1 2 3 4 5 6 7 8 9 10
float AreaofTri (float b1, float h1)
{
float Area;
Area = ((b1 * h1) / 2);
if (b1 == 0 || h1 == 0)
cout << "Invalid Entry. Try Again..";
else
cout << "The area of this triangle is: " << Area;
return Area;
}
you can put this into a header and all that is needed is the proper inputs and the function call to be placed in main and this should work.
If you were asked to include the header file #include <cmath>
I don't think there is any need to write a function to calculate the area of a triangle cause the included header is supposed to contain a function to do that. but if it doesn't, then the included header file is useless in the code you wrote.
I needed some refreshing before looking further into this.
for calculating a three sided triangle and using the <cmath> header i rewrote the function as follows;