logo image

C++ program to calculate trapezoid circumference

Views: 13

Following program shows you how to calculate trapezoid circumference. This program gets trapezoid bases and sides from user and calculates circumference and prints it using following formula Circumference = base1 + base2 + side1 +side2

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

int main() {
	float trapezoidBase1;
	float trapezoidBase2;
	float trapezoidSide1;
	float trapezoidSide2;

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

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

	std::cout << "Please enter side1 of trapezoid:";
	std::cin >> trapezoidSide1;

	std::cout << "Please enter side2 of trapezoid:";
	std::cin >> trapezoidSide2;

	float circumferenceOfTrapezoid =
		trapezoidBase1 + trapezoidBase2 + trapezoidSide1 + trapezoidSide2;

	std::cout << "Circumference of trapezoid is: " << circumferenceOfTrapezoid;
}

Output:

Please enter base1 of trapezoid: 12
Please enter base2 of trapezoid: 15
Please enter side1 of trapezoid: 19
Please enter side2 of trapezoid: 22
Circumference of trapezoid is: 68