Question: Integer colorIntensity is read from input. Complete the try block to throw a runtime error exception with the message Bad input for color intensity if

Integer colorIntensity is read from input. Complete the try block to throw a runtime error exception with the message "Bad input for color intensity" if colorIntensity is < 0 or > 255.

Ex: If input is 236, then the output is:

Color intensity: 236 

Ex: If input is 410, then the output is:

Error: Bad input for color intensity

#include #include using namespace std;

int main() { int colorIntensity;

cin >> colorIntensity;

try { if (colorIntensity < 0 || colorIntensity > 255) { throw /* Your code goes here */; } cout << "Color intensity: " << colorIntensity << endl; } catch (runtime_error& excpt) { cout << "Error: " << excpt.what() << endl; }

return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!