Advertisement
Sha_A

switch with do while !

Feb 20th, 2020
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. /*write a program to calculate the area of one rectangle and one square in one program with using switch case */
  2.  
  3. #include <iostream>
  4. #include<conio.h>
  5. using namespace std;
  6. int main()
  7. {
  8.   int a,b,h,n;
  9.  
  10.   do{
  11.   cout<<"Enter 1 for Square or 2 for Rectangle  ";
  12.   cin>>n;
  13.    
  14.   cout<<"A = ";
  15.   cin>>a;
  16.  
  17.   cout<<"B =";
  18.   cin>>b;
  19.  
  20.   cout<<"H =";
  21.   cin>>h;
  22.  
  23. switch (n)
  24. {
  25. case 1:
  26.  
  27.   a=4*b;
  28.     cout<<"area of square is "<<a<<endl;
  29. break;
  30.  
  31. case 2:
  32. a=2*b*h;
  33.    cout<<"area of rectangle is "<<a<<endl;
  34. break;
  35.  
  36. default:
  37.    cout<<"bug\n";
  38. break;
  39. }
  40. }
  41. while ( n != 2 );  
  42.  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement