Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*write a program to calculate the area of one rectangle and one square in one program with using switch case */
- #include <iostream>
- #include<conio.h>
- using namespace std;
- int main()
- {
- int a,b,h,n;
- do{
- cout<<"Enter 1 for Square or 2 for Rectangle ";
- cin>>n;
- cout<<"A = ";
- cin>>a;
- cout<<"B =";
- cin>>b;
- cout<<"H =";
- cin>>h;
- switch (n)
- {
- case 1:
- a=4*b;
- cout<<"area of square is "<<a<<endl;
- break;
- case 2:
- a=2*b*h;
- cout<<"area of rectangle is "<<a<<endl;
- break;
- default:
- cout<<"bug\n";
- break;
- }
- }
- while ( n != 2 );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement