Answer to Question #169460 in C++ for Mohamed abokor

Question #169460

Write a float function triangle that computes the area of triangle using its two formal parameters h and w, where h is height and w is the length of bases of triangle?


1
Expert's answer
2021-03-06T08:17:13-0500
#include <iostream>

float triangle(float h, float w)
{
    return h * w / 2;
}

int main()
{
    std::cout << "Please enter the height and the length of bases of triangle: ";
    float h, w;
    std::cin >> h >> w;

        if(!std::cin || h < 0 || w < 0)
        {
            std::cout << "Bad input\n";
            return 1;
        }

    std::cout << "The area of triangle is " << triangle(h, w) << "\n";
    
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS