Write a program in C++ to find area of Triangle, Rectangle or Circle using IF ELSE (must be menu driven)

#include <iostream.h>
#include <conio.h>

int main() {
        
    int shape, a, b;
    char ans;
    
    Repeat: 
    system("CLS");
    cout << "Select Shape:" << endl;
    cout << "1.Triangle" << endl;
    cout << "2.Rectangle" << endl;
    cout << "3.Circle" << endl;
    
    cin >> shape;
    
    if(shape==1) {
       cout << "Base: ";
       cin >> a;
       cout << "Altitude: ";
       cin >> b;
       cout << endl << "Area of Triangle: " << 0.5*a*b;
    } else if(shape==2) {
       cout << "Length: ";
       cin >> a;
       cout << "Breadth: ";
       cin >> b;
       cout << endl << "Area of Rectangle: " << a*b;           
    } else if(shape==3) {           
       cout << "Radius: ";
       cin >> a;
       cout << endl << "Area of Circle: " << 3.14*a*a;  
    } else {
       cout << "Invalid Shape";       
    }
    
    cout << endl << "Do you want more calculation? (y/n)";
    cin >> ans;
    
    if (ans=='y') {
       goto Repeat;
    }
    
    getch();
    return 0;
}


Output:

{ 1 comments... read them below or add one }

  1. This comment has been removed by a blog administrator.

    ReplyDelete

Contact Form

Name

Email *

Message *

Followers