Answer to Question #253171 in C++ for Kris

Question #253171

create a plan for a program that will let the user to choose from circle or a rectangle.Must compute the area.


1
Expert's answer
2021-10-18T13:53:52-0400
#include <iostream>


using namespace std;


const double PI = 3.14;


int main()
{
    cout << "Please select a shape:" << endl;
    cout << "1 - Circle" << endl;
    cout << "2 - Rectangle" << endl;


    cout << endl << "Your choice: ";
    int choice;
    cin >> choice;


    if(choice !=1 && choice !=2)
        cout << "Invalid choice";
    else
    {
        double area;
        if(choice == 1)
        {
            cout << "radius = ";
            double radius;
            cin >> radius;


            area = PI*radius*radius;
        }
        else
        {
            cout << "width = ";
            double width;
            cin >> width;


            cout << "length = ";
            double length;
            cin >> length;


            area = length*width;
        }
        cout << endl << "Area = " << area << endl;
    }
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS