1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
#include <iostream>
using namespace std;
#include<cmath>
int main()
{
int number;
double radious_circle, circle_area, length_rectangle, width_rectangle, rectangle_area, triangle_base, triangle_height, triangle_area;
cout<<"Enter 1,2,3 or 4";
cin>>number;
switch(number)
{
case1: cout<<"Please enter the radious of a circle and I will calculate the area";
cin>>radious_circle;
if(radious_circle>=0)
{
circle_area=(3.14159)*pow(radious_circle,2);
cout<<"The area of the circle is" <<circle_area<<endl;
}
else
{
cout<<"Please enter positive numbers only!";
}
break;
case2: cout<<"Please enter the length and width of a rectangle and I will calculate the area";
cin>>length_rectangle>>width_rectangle;
if(length_rectangle>=0 && width_rectangle>=0)
{
rectangle_area = length_rectangle*width_rectangle;
cout<<"The area of the rectangle is"<<rectangle_area<<endl;
}
else
{
cout<<"Please enter positive numbers only!";
}
break;
case3: cout<<"Please enter the length of a triangle's base and it's height and I will calculate the area";
cin>>triangle_base>>triangle_height;
if(triangle_base>=0 && triangle_height>=0)
{
triangle_area=(triangle_base*triangle_height)/2;
cout<<"The area of the triangle is"<<triangle_area;
}
else
{
cout<<"Please enter positive numbers only!";
}
break;
case4: cout<<"This program has ended, Thank you!";
break;
default: cout<<"You did not enter 1, 2, 3, or 4";
}
return 0;
}
| |