What happens when you set an int or double value to less than the minimum? I need my program to recognize when a number is smaller then the minimum, and then set the value to equal the minimum instead. This behavior is not the default...
#include <iostream>
using namespace std;
int main(){
int a = -1;
cout<< "1. a is " << a <<endl;
a = -12;
cout<< "2. a is " << a <<endl;
a = -123;
cout<< "3. a is " << a <<endl;
a = -1234;
cout<< "4. a is " << a <<endl;
a = -12345;
cout<< "5. a is " << a <<endl;
a = -123456;
cout<< "6. a is " << a <<endl;
a = -1234567;
cout<< "7. a is " << a <<endl;
a = -12345678;
cout<< "8. a is " << a <<endl;
a = -123456789;
cout<< "9. a is " << a <<endl;
a = -1234567890;
cout<< "10. a is " << a <<endl;
a = -12345678901;
cout<< "11. a is " << a <<endl;
a = -123456789012;
cout<< "12. a is " << a <<endl;
a = -1234567890123;
cout<< "13. a is " << a <<endl;
a = -12345678901234;
cout<< "14. a is " << a <<endl;
int b = 2147483648;
cout<< "\n\nb is " << b <<endl;
cout<< "b-1 is " << b-1 <<endl;
cout<< "b-1+1 is " << b-1+1 <<endl;
cout<< "b+1 is " << b+1 <<endl;
b = b-1;
cout<< "b-1+1 instrinsic is " << b+1 <<endl;
return 0;
}
which gives warnings:
"
intminimum.cpp: In function ‘int main()’:
intminimum.cpp:26: warning: overflow in implicit constant conversion
intminimum.cpp:28: warning: overflow in implicit constant conversion
intminimum.cpp:30: warning: overflow in implicit constant conversion
intminimum.cpp:32: warning: overflow in implicit constant conversion
"
which outputs:
"
1. a is -1
2. a is -12
3. a is -123
4. a is -1234
5. a is -12345
6. a is -123456
7. a is -1234567
8. a is -12345678
9. a is -123456789
10. a is -1234567890
11. a is 539222987
12. a is 1097262572
13. a is -1912276171
14. a is -1942892530
b is -2147483648
b-1 is 2147483647
b-1+1 is -2147483648
b+1 is -2147483647
b-1+1 instrinsic is -2147483648
"