diff --git a/CPP019_CalculateArea_Exercise.cpp b/CPP019_CalculateArea_Exercise.cpp index 91c97e1..f79ecb7 100644 --- a/CPP019_CalculateArea_Exercise.cpp +++ b/CPP019_CalculateArea_Exercise.cpp @@ -1,96 +1,199 @@ -/** - * Author: Tridib Samanta - * Created: 15.01.2020 - **/ - #include + #define PI 3.14 + using namespace std; -void initMenu(); + + +void menu(); + void menuDecision(int); + double areaCircle(double); + double areaSquare(double); + double areaRectangle(double,double); + double areaTriangle(double,double); +bool check_for_positive(double); + + int main() { + + int choice; + char cont; + + do { - //system("cls"); - initMenu(); + + menu(); + cin>>choice; + + menuDecision(choice); + + cout<<"Do you want to continue ? (Y/N)"<>cont; + } while(cont=='Y'||cont=='y'); + + return 0; + } -void initMenu() { - cout<<"Select from the options :"<>r; - areaCircle(r); + if(check_for_positive(r)){ + cout << "Cannot find area for zero and negative." << endl; + }else{ + + areaCircle(r); + } + break; + case 2: + cout<<"Enter a side of the square : "<>a; - areaSquare(a); + if(check_for_positive(a)){ + cout << "Cannot find area for zero and negative." << endl; + }else{ + + areaSquare(a); + } + break; + case 3: - cout<<"Enter the width and height of the rectangle : "<>a>>b; - areaRectangle(a,b); + + cout<<"Enter the width of Rectangle: "; + cin >> a; + cout<<"Enter the height of Rectangle: "; + cin >> b; + if(check_for_positive(a)||check_for_positive(b)){ + cout << "Cannot find area for zero and negative." << endl; + }else{ + + areaRectangle(a,b); + } + break; + case 4: - cout<<"Enter the base and height of the triangle : "<>a>>h; - areaTriangle(a,h); + + cout<<"Enter the base of the triangle : "; + + cin>>a; + cout<<"Enter the height of triangle: "; + cin >> h; + if(check_for_positive(a)||check_for_positive(h)){ + cout << "Cannot find area for zero and negative." << endl; + }else{ + + areaTriangle(a,h); + } + break; + default: + cout<<"Wrong choice !"<