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

Using C++ program Use throw, try, catch to implement the following. 1. the quest

ID: 3778063 • Letter: U

Question

Using C++ program

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 <iostream>
#include <iomanip>
#include <exception>

using namespace std;

int main()
{
   //Declaring variables
   int number;
  
   while(true)
   {
       cout<<"Do you want to be NICE or EVIL? "<<endl;
   //Getting the how many numbers user want to enter
   cout<<" Enter an integer between 0 - 10:";
   cin>>number;
try
   {
   if(number==1)
   {
       cout<<"Super Evil"<<endl;
       break;
   }
   else if(number==2)
   {
       cout<<"Super Nice"<<endl;
       break;
   }
   else if(number<5)
   {
   throw "Think twice, why not choose to be nice?";
}
   else if(number>=5)
   {
   cout<<"Good Job Thank You"<<endl;
   break;
   }

}
catch (const char* strException)
{
   //Displaying the Exception
cerr << "Error: " << strException << endl;
continue;
}  
   }
      

  
   return 0;
}

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