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 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)
Area = ((b1 * h1) / 2);
if (b1 == 0 || h1 == 0)
cout << "Invalid Entry. Try Again..";
cout << "The area of this triangle is: " << 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.