Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Use throw, try, catch to implement the following. 1. the question appears in the

ID: 3777458 • Letter: U

Question

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!"

Explanation / Answer

#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!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote