Use throw try catch to implement the following 1 the questio
Use throw, try, catch to implement the following.
1. the question appears in the console, \'Do you want to be NICE or EVIL? Enter an integer between 0 - 10 to represent the answer. 1 means super EVIL and 10 means super NICE.\'
2. User inputs an integer.
3. If this number is smaller that 5, there are suggesstions pop up in the console: \' Think twice, why not choose to be nice?\'
4. When the user enters a number that is equal to or greater than 5, words pop up in the console as \"Good job! Thank you!\"
Solution
#include<bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{
cout<<\"Do you want to be NICE or EVIL?\ Enter an integer between 0 - 10 to represent the answer\ \";
int n;
cin>>n;
try
{
if(n<5)
{
cout<<\"Think twice, why not choose to be nice?\ \";
throw n;
}
else
throw n;
}
catch(int n)
{
if(n>5)
{
cout<<\"Good job! Thank you!\ \";
}
else
{ cin>>n;
if(n>5)
{
cout<<\"Good job! Thank you!\ \";
}
}
}
return 0;
}
====================================================
akshay@akshay-Inspiron-3537:~/Chegg$ g++ thr.cpp
akshay@akshay-Inspiron-3537:~/Chegg$ ./a.out
Do you want to be NICE or EVIL?
Enter an integer between 0 - 10 to represent the answer
1
Think twice, why not choose to be nice?
6
Good job! Thank you!

