C++ program to find area and perimeter of rectangle using switch

Area and perimeter of rectangle using switch

C++ program to find area and perimeter of rectangle using switch.Switch statement compare the value with each case. If their is a match of value then that case will be executed otherwise a default case will be executed.

Program

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
char ch;
float l,b,area,perimeter;
cout<<"Options are:- ";
cout<<"\n 1.area";
cout<<"\n 2.perimeter"<<endl;
cout<<"Enter your choice:- ";
cin>>ch;
 if(ch=='1' || ch=='2')
  {
  cout<<"Enter length and breadth of rectangle:- "<<endl;
  cin>>l>>b;
  }
  switch(ch)
   {
    case '1': area=l*b;
	cout<<"Area of rectangle is:- "<<area;
	      break;
    case '2': perimeter=2*(l+b);
	cout<<"Perimter of rectangle is:- "<<perimeter;
	      break;
    default : cout<<"Sorry Wrong Choice";

  }

  getch();
  }

OUTPUT

When case 1 is executed.

Area and perimeter of rectangle using switch


When case 2 is executed

Area and perimeter of rectangle using switch


Comment below if you are facing any problem


Also read

C++ program to find area and perimeter of rectangle using Classes
C++ program to find greatest between three numbers using single inheritance
C++ program of multilevel inheritance
Multiple inheritance program in c++


Summary
C++ program to find area and perimeter of rectangle using switch
Article Name
C++ program to find area and perimeter of rectangle using switch
Description
This program illustrate the concept to find area and perimeter of rectangle using switch.Switch statement compare the value with each case.
Author
Publisher Name
Scanfcode
Publisher Logo

Leave a Reply

Your email address will not be published. Required fields are marked *