Rearrange the code to define a function"foo", wich throws an exception with a value of "100" if its parameter is greater than 999. The "foo" catches its exceptions and prints "error" to the screen.
# include <iostream>
# include <stdexcept>
void foo (int number)
{
try
{
std::cout << "enter number: \n";
std::cin >> number;
if (number <= 999)
{
std::cout << "the number is: " << number << "\n";
}
else
{
throw std::out_of_range("100");
//console prints same for number entered == 100, ...
// ... so something additioal would be good
}
}
catch (const std::exception& e)
{
std::cerr << e.what();
}
}
int main()
{
int num1{}, num2{};
foo(num1);
foo(num2);
}