#include <iostream>
using namespace std;

int main() 
{
   int age;
  try
  {
    cout<<"Enter age";
    cin>>age;
    if (age >= 18) 
    {
      cout << "Access granted - you are old enough.";
    } 
    else 
    {
      throw (age);
    }
  }
  catch (int myNum) 
{
    cout << "Access denied - You must be at least 18 years old.\n";
    cout << "Age is: " << myNum;  
  }
  return 0;
}

     
           
Note: Need to be arranged in compiler after copied
   

 OutPut:

Output1:
Enter age20
Access granted - you are old enough.
Output2:
Enter age12
Access denied - You must be at least 18 years old.
Age is: 12