upsidedown

exception handling r.p

Apr 20th, 2012
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.04 KB | None | 0 0
  1. #include<iostream.h>
  2. void enter();
  3. void divbz();
  4.  
  5. void enter()
  6. {
  7.     int i=0,counta=0,countb=0;
  8.     int c,d;
  9.     float a,b;
  10.     cout<<"enter two float values\n";
  11.     cin>>a>>b;
  12.     c=(int)a;
  13.     d=(int)b;
  14.     a=a-c;
  15.     b=b-d;
  16.     try
  17.     {
  18.  
  19.         if((a==0)||(b==0))
  20.             throw 1;
  21.         else
  22.             throw 0;
  23.     }
  24.     catch(int x)
  25.     {
  26.         switch(x)
  27.         {
  28.         case 0:
  29.             cout<<"correct data type entered\n";
  30.             break;
  31.  
  32.         case 1:
  33.             cout<<"wrong data type entered \n";
  34.             break;
  35.  
  36.         default:
  37.             break;
  38.         }
  39.     }
  40. }
  41.  
  42. void divbz()
  43. {
  44.     int z,x;
  45.     cout<<"enter two numbers to divide them\n";
  46.     cin>>z>>x;
  47.     try
  48.     {
  49.         if(x==0)
  50.             throw x;
  51.         else
  52.             cout<<"the quotient is "<<(z/x)<<endl;
  53.     }
  54.     catch(int m)
  55.     {
  56.         cout<<"cannnot divide the divisor is "<<m<<endl;
  57.     }
  58. }
  59.  
  60. int main()
  61. {
  62.     enter();
  63.     divbz();
  64.     return 0;
  65. }
  66.  
  67. OUTPUT:
  68. enter two float values
  69. 3.461
  70. 2.615
  71. correct data type entered
  72. enter two numbers to divide them
  73. 4
  74. 0
  75. cannnot divide the divisor is 0
  76.  
  77. enter two float values
  78. 4
  79. 2
  80. wrong data type entered
  81. enter two numbers to divide them
  82. 456
  83. 421
  84. the quotient is 1
Advertisement
Add Comment
Please, Sign In to add comment