BHXSpecter

Untitled

Nov 21st, 2011
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     int dividend, divisor = 1, quotient;
  9.    
  10.     string inpStr = "The input stream is in the fail state.";
  11.    
  12.     try
  13.     {
  14.         cout << "Enter the dividend: ";
  15.         cin >> dividend;
  16.         cout << endl;
  17.        
  18.         cout << "Enter the divisor: ";
  19.         cin >> divisor;
  20.         cout << endl;
  21.        
  22.         if (divisor == 0)
  23.             throw divisor;
  24.         else if (divisor < 0)
  25.             throw string("Negative divisor.");
  26.         else if (!cin)
  27.             throw inpStr;
  28.        
  29.         quotient = dividend / divisor;
  30.        
  31.         cout << "Quotient = " << quotient << endl;
  32.     }
  33.     catch (int x)
  34.     {
  35.         cout << "Division by " << x << endl;
  36.     }
  37.     catch(string s)
  38.     {
  39.         cout << s << endl;
  40.     }
  41.    
  42.     return 0;
  43. }
  44.  
Advertisement
Add Comment
Please, Sign In to add comment