create a plan for a program that will let the user to choose from circle or a rectangle.Must compute the area.
#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;
}
Comments
Leave a comment