#include<iostream>
using namespace std;
int main()
{
int age;
cout<<"please enter your age:";
cin>>age;
try
{
if(age>18)
{
cout<<"Access granted - you are old enough."<<endl;
}
else
{
throw(age); //here i throw the execption
}
}
catch(int myNum) //here i catch the execption
{
cout<<"Access denied - You must be at least 18 years old.\n";
cout<<"Age is: "<< myNum;
}
}
No comments:
Post a Comment