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
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
Get step-by-step solutions from verified subject matter experts
