Ask Question
20 March, 14:53

The area of a rectangle is the rectangle's length times its width.

Design a program that asks for the length and width of two rectangles. The program should tell the user which rectangle has the greater area, or whether the areas are the same.

+5
Answers (1)
  1. 20 March, 18:25
    0
    Following are program to this question:

    #include / /defining header file

    using namespace std;

    int main () / /defining main method

    {

    double len1, len2, wid1, wid2, area1, area2; / /defining double variable

    cout << "Enter first rectangle length: "; / /print message

    cin >> len1; //input first rectangle length value

    cout << "Enter first rectangle width: "; //print message

    cin >> wid1; / /input first rectangle width value

    area1 = len1*wid1; / /calculate area and holds its value

    cout << "Enter second rectangle length: "; //print message

    cin >> len2; / /input second rectangle length value

    cout << "Enter second rectangle width: "; //print message

    cin >> wid2; / /input second rectangle width value

    area2 = len2*wid2; / /calculate area and holds its value

    if (area1 > area2) / /check condition area1 value is greater then area2

    {

    cout << "First rectangle area value is greater"; //print message

    }

    else if (area2 > area1) / /check condition area2 value is greater then area1

    {

    cout << "Second rectangle area value is greater"; //print message

    }

    else / /else block

    {

    cout << "both rectangle area is same"; //print message

    }

    return 0;

    }

    Output:

    Enter first rectangle length: 3

    Enter first rectangle width: 5

    Enter second rectangle length: 5

    Enter second rectangle width: 3

    both rectangle area is same

    Explanation:

    The description of the above program can be described as follows:

    In the given code, the double variable is declared, which is "len1, len2, wid1, wid2, area1, and area2". In the next line, a message is a print, that accepts "len1 and wid1" value in the next line, the area variable is used that calculates area1. In the next step, the "len2 and wid2" variable is used, that accepts values and calculates its area, and in the next line, the conditional statement is used that checks its value. In the if the block it uses both area1 and area2 value, that checks area1 is greater then area2, it is will print first rectangle area is greater. Otherwise, it will go to else if block, that checks area2 is greater then area1, it is will print second rectangle area is greater. In the else section, it will print both equal areas.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “The area of a rectangle is the rectangle's length times its width. Design a program that asks for the length and width of two rectangles. ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers