#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int n;
cout << "Geometry Calculator" <<endl <<endl;
cout << "1. Calculate the Area of a Circle" <<endl;
cout << "2. Calculate the Area of a Rectangle" <<endl;
cout << "3. Calculate the Area of a Triangle" <<endl;
cout << "4. Quit" <<endl;
cout << "Enter 1,2,3, or 4: ";
cin >> n;
if (n==1)
{
float pi= 3.14159;
float r;
cout <<"Enter the radius of the circle: ";
cin >> r;
if(r<0)
{ cout << "ERROR! Enter a positive number.\n";}
if (r>0)
cout << "The area of the circle is " <<fixed <<setprecision(2) << (2*pi*r) << " square\n";
}
if (n==2)
{
float l,w;
cout << "Enter the length of the rectangle: ";
cin >> l;
if(l<0)
{cout << "ERROR!Enter a positive number.\n";}
cout << "Enter the width of the rectangle: ";
cin >> w;
if(w<0)
{cout << "ERROR! Enter a positive number.\n";}
if (l>=0&&w>=0)
cout << "The area of the rectangle is " << l*w << " sqaure\n";
else if (l<0||w<0)
cout << "Error! Enter a positive number.";
}
if (n==3)
{
float base,height;
cout <<"Enter the base of the triangle: ";
cin>> base;
if(base<0)
{ cout <<"ERROR! Enter a positive number.\n";}
cout <<"Enter the height of the triangle: ";
cin>> height;
if(height<0)
{cout << "ERROR! Enter a positive number.\n";}
if (base>=0&&height>=0)
cout << "The area of the triangle is " << base*height <<" square\n";
else if (base<0||height<0)
cout << "Error! Enter a positive number.";
}
if (n==4)
{cout << "End of program.\n";}
if (n>=5||n<=0)
{cout << "Not in range!!!\n";}
return 0;
}