I need to debug the program below.. Areas of Rectangles #include <iostream> int
ID: 3757750 • Letter: I
Question
I need to debug the program below..
Areas of Rectangles
#include <iostream>
int main()
{
double width1; // Width of rectangle #1
double length1; // Length of rectangle #1
double area1; // Area of rectangle #1
double width2; // Width of rectangle #2
double Length2; // Length of rectangle #2
double area2 // Area of rectangle #2
// Get the width of rectangle #1
cout << "Enter the width of the first rectangle: ";
cin >> width1;
// Get the length of rectangle #1
cout << "Enter the length of the first rectangle: ";
cin << length1;
// Get the width of rectangle #2
cout << Enter the width of the second rectangle : ;
cin >> width2,
// Get the length of rectangle #2
cOut << "Enter the length of the second rectangle: ":
cin >> "length2";
// Calculate the areas of the two rectangles.
width1 * length1 = area1;
width2 * length2 = area2;
// Determine which rectangle has the greater
// area, or whether they have equal area.
if (area1 > area2);
cout << Rectangle #1 has the greater area. / n";
else if (area2 > area1);
cout << "Rectangle #2 has the greater area./n";
esle
cout << "Both rectangles have the same area./n";
Return O;
};
Explanation / Answer
#include <iostream>
using namespace std;
int main()
{
double width1; // Width of rectangle #1
double length1; // Length of rectangle #1
double area1; // Area of rectangle #1
double width2; // Width of rectangle #2
double length2; // Length of rectangle #2
double area2 ; // Area of rectangle #2
// Get the width of rectangle #1
cout << "Enter the width of the first rectangle: ";
cin >> width1;
// Get the length of rectangle #1
cout << "Enter the length of the first rectangle: ";
cin >> length1;
// Get the width of rectangle #2
cout << "Enter the width of the second rectangle : ";
cin >> width2,
// Get the length of rectangle #2
cout << "Enter the length of the second rectangle: ";
cin >> length2;
// Calculate the areas of the two rectangles.
area1 = width1*length1 ;
area2 = width2*length2 ;
// Determine which rectangle has the greater
// area, or whether they have equal area.
if (area1 > area2)
cout << "Rectangle #1 has the greater area. ";
else if (area2 > area1)
cout << "Rectangle #2 has the greater area. ";
else
cout << "Both rectangles have the same area. ";
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.