163k views
1 vote
c++ Write a program to calculate the area and perimeter of a number of rectangles. You will use a for loop in this program.

User Shezi
by
8.3k points

1 Answer

4 votes

Answer:

Here's a C++ program that calculates the area and perimeter of a number of rectangles using a "for" loop: dont trust me too much

Step-by-step explanation:

#include <iostream>

using namespace std;

int main()

{

int n;

cout << "Enter the number of rectangles to calculate area and perimeter for: ";

cin >> n;

cout << endl;

double length, width, area, perimeter;

for (int i = 1; i <= n; i++)

{

cout << "Rectangle " << i << ":" << endl;

cout << "Enter length and width: ";

cin >> length >> width;

area = length * width;

perimeter = 2 * (length + width);

cout << "Area: " << area << endl;

cout << "Perimeter: " << perimeter << endl << endl;

}

return 0;

}

Here's how the program works:

The user is prompted to enter the number of rectangles they want to calculate the area and perimeter for.

For each rectangle, the user is prompted to enter the length and width.

The program then calculates the area and perimeter using the entered values.

The values of the calculated area and perimeter are printed for each rectangle.

Note that this program assumes that the length and width entered are positive real numbers.

User MonOve
by
8.5k points