Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int Factorial(int input)
- {
- if (input > 1)
- return input * Factorial(input - 1);
- else if (input < 0)
- throw NegativeException(input);
- else
- return 1;
- }
- int main()
- {
- using std::cout;
- using std::cin;
- int input;
- while (1)
- {
- try
- {
- cout << "Please enter an integer to find its factorial: ";
- cin >> input;
- cout << "The factorial of " << input << " is " << Factorial(input) << endl;
- }
- catch (const std::bad_typeid & ex)
- {
- cout << "Exception: " << ex.what();
- cout << "Try another integern" << endl;
- }
- catch (NegativeException& ex1)
- {
- cout << ex1.what();
- cout << "Try another integern" << endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement