Facebook
From Tanvir, 1 Month ago, written in C++.
Embed
Download Paste or View Raw
Hits: 209
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5.   try {
  6.     int age = 15;
  7.     if (age >= 18) {
  8.       cout << "Access granted - you are old enough.";
  9.     } else {
  10.       throw (age);
  11.     }
  12.   }
  13.   catch (int myNum) {
  14.     cout << "Access denied - You must be at least 18 years old.n";
  15.     cout << "Age is: " << myNum;  
  16.   }
  17.   return 0;
  18. }