Write a program that gets a choice from user if choice is ‘R’ program should calculate area of a rectangle and display it, if the choice is ‘T’ then it shall calculate area of circle and display it.
#include <bits/stdc++.h>
using namespace std;
int main()
{
int length,breadth,radius,area_rect,area_circle;
string choice;
cout<<"Enter your choice: ";
cin>>choice;
if (choice == "R")
{
cout<<"Enter the length of rectangle:";
cin>>length;
cout<<"Enter the breadth of rectangle:";
cin>>breadth;
area_rect = length * breadth;
cout<<"Area of Rectangle: "<<area_rect;
}
else if (choice == "T")
{
cout<<"Enter radius of circle: ";
cin>>radius;
area_circle = 3.14 * radius * radius;
cout<<"Area of Circle:"<<area_circle;
}
return 0;
}
Comments
Leave a comment