Haval1

Last Example about switch&do while

May 11th, 2018
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.51 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3. void op_fun(int c)
  4. {
  5.     int x,y;
  6.     switch(c)
  7.     {
  8.         //if the user choose 1
  9.         case 1:
  10.             cout<<"\n-----------------------------------------------\n";
  11.             cout<<"Addition";
  12.             cout<<"\n-----------------------------------------------\n";
  13.             cout<<"Enter First Number : "; cin>>x;
  14.             cout<<"Enter Second Number : "; cin>>y;
  15.             cout<<"The Resualt is : "<<x+y<<endl;
  16.             cout<<"\n-----------------------------------------------\n";
  17.         break;
  18.         //if the user choose 2
  19.         case 2:
  20.             cout<<"\n-----------------------------------------------\n";
  21.             cout<<"Subtraction";
  22.             cout<<"\n-----------------------------------------------\n";
  23.             cout<<"Enter First Number : "; cin>>x;
  24.             cout<<"Enter Second Number : "; cin>>y;
  25.             cout<<"The Resualt is : "<<x-y<<endl;
  26.             cout<<"\n-----------------------------------------------\n";
  27.         break;
  28.         //if the user choose 3
  29.         case 3:
  30.             cout<<"\n-----------------------------------------------\n";
  31.             cout<<"Multiple";
  32.             cout<<"\n-----------------------------------------------\n";
  33.             cout<<"Enter First Number : "; cin>>x;
  34.             cout<<"Enter Second Number : "; cin>>y;
  35.             cout<<"The Resualt is : "<<x*y<<endl;
  36.             cout<<"\n-----------------------------------------------\n";
  37.         break;
  38.        
  39.         default:
  40.             cout<<"End of programm ";
  41.            
  42.     }
  43. }
  44. int main()
  45. {
  46.     int c;
  47.     //we uses do while for looping this
  48.     do
  49.     {
  50.         cout<<"1 :Addition \t 2 :Subtraction \t 3 :Multiple \t 4 :Exit \n";
  51.         cout<<"Choose : ";
  52.         cin>>c;
  53.         op_fun(c); 
  54.     }while(c!=4);
  55. }
Advertisement
Add Comment
Please, Sign In to add comment