Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- double getCircleArea(double radius){
- return 2 * 3.14 * radius;
- }
- double getRectangleArea(double length, double width){
- return length * width;
- }
- double getTriangleArea(double base, double height){
- return base * height * 0.5;
- }
- int main()
- {
- cout<<"Geometry Calculator"<<endl;
- cout<<"1. Calculate the Area of a Circle \n2. Calculate the Area of a Rectangle \n3. Calculate the Area of a Triangle \n4. Quit"<<endl;
- cout<<"Enter your choice (1-4): "<<endl;
- int choice;
- cin >> choice;
- double area;
- while(choice != 4){
- switch(choice) {
- case 1: cout<<"Please enter the radius of Circle"<<endl;
- double radius;
- cin >> radius;
- if(radius<=0) {
- cout<<"The radius can not be less than zero."<<endl;
- } else {
- area = getCircleArea(radius);
- cout<<"The area of the Circle is: "<<area<<endl;
- }
- break;
- case 2:
- cout<<"Please enter the length of Rectangle"<<endl;
- double length;
- cin >> length;
- cout<<"Please enter the width of Rectangle"<<endl;
- double width;
- cin >> width;
- if(length<=0 || width<=0) {
- cout<<"Only enter positive values for length and width"<<endl;
- } else {
- area = getRectangleArea(length, width);
- cout<<"The area of the Rectangle is: "<<area<<endl;
- }
- break;
- case 3:
- cout<<"Please enter the base of Triangle"<<endl;
- double base;
- cin >> base;
- cout<<"Please enter the height of Triangle"<<endl;
- double height;
- cin>>height;
- if(base<=0||height<=0) {
- cout<<"Only enter positive values for base and height"<<endl;
- } else {
- area = getTriangleArea(base, height);
- cout<<"The area of the Rectangle is: "<<area<<endl;
- }
- case 4:
- cout<<"Exit"<<endl;
- break;
- default:
- cout<<"Error: The range should be between 1 and 4"<<endl;
- }
- cout<<"1. Calculate the Area of a Circle \n2. Calculate the Area of a Rectangle \n3. Calculate the Area of a Triangle \n4. Quit"<<endl;
- cout<<"Enter your choice (1-4): "<<endl;
- cin >> choice;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement