Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. int Factorial(int input)
  2. {
  3. if (input > 1)
  4. return input * Factorial(input - 1);
  5. else if (input < 0)
  6. throw NegativeException(input);
  7. else
  8. return 1;
  9. }
  10.  
  11. int main()
  12. {
  13. using std::cout;
  14. using std::cin;
  15. int input;
  16.  
  17. while (1)
  18. {
  19. try
  20. {
  21. cout << "Please enter an integer to find its factorial: ";
  22. cin >> input;
  23. cout << "The factorial of " << input << " is " << Factorial(input) << endl;
  24. }
  25. catch (const std::bad_typeid & ex)
  26. {
  27. cout << "Exception: " << ex.what();
  28. cout << "Try another integern" << endl;
  29. }
  30. catch (NegativeException& ex1)
  31. {
  32. cout << ex1.what();
  33. cout << "Try another integern" << endl;
  34. }
  35. }
  36.  
  37. return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement