C++ program to calculate trapezoid area

Views: 698   

Following program shows you how to calculate trapezoid area.
This program gets trapezoid base and height from user and calculates area and prints it using following formula
Area = (base1 + base2) X height /2

#include <iostream>
#include <math.h>

int main() {
    float trapezoidBase1;
    float trapezoidBase2;
    float trapezoidHeight;

    std::cout << "Please enter base1 of trapezoid:";
    std::cin >> trapezoidBase1;

    std::cout << "Please enter base2 of trapezoid:";
    std::cin >> trapezoidBase2;

    std::cout << "Please enter height of trapezoid:";
    std::cin >> trapezoidHeight;

    float areaOfTrapezoid =
        (trapezoidBase1 + trapezoidBase2) * trapezoidHeight / 2;

    std::cout << "Area of trapezoid is: " << areaOfTrapezoid;


Please enter base1 of trapezoid: 12
Please enter base2 of trapezoid: 19
Please enter height of trapezoid: 25
Area of trapezoid is: 387.5
On By