Lol I tried to find the solution for you looked around for about 2hrs. I see alot of ways to test if a multiplication or addition is above limits using.
but I couldn't find any way to combine this with
if((x*x) > std::numeric_limits<int>::max())
So my only guess would be putting the input into a string or larger bit variable like a double and then checking if it's greater than the int max. Such as
I'm sure this wouldn't be the most efficient method, but I've tried alot of combinations and the only way to glitch it out that I've found is inputing a character instead of a number, or going over the limits of double. (which a string would probably solve, but of course the code would get a little lengthy.) Of course this obviously doesn't check for a negative overflow either.
using namespace std;
int main(int argc, char *argv)
std::cout<<" max int value = "<<std::numeric_limits<int>::max()<<endl;
while((a) > std::numeric_limits<int>::max() )
std::cout << "overflow" << std::endl;
std::cout << "please input a non overflow number."<<endl;
std::cout<< "Your number is within the limits of an int"<<endl;
int b = a;