//This program display the minimum and the maximum of 6 numbers
using namespace std;
short int number, min=65535,max=0,counter=0;
cout << "Enter number:";
cout <<"Minimum of the numbers:"<<min<<endl<<"Maximum of the numbers:"<<max<<endl;
It always display minimum as -1.
Can somebody tell me why???????
Because the value of short int is from -32,768 to 32,767. So, to use the 65535, change to just int.
If you cout the variable, short int min, you'll find its value is -1.
Last edited on
@whitenite1 you are simply differentiating between signed and unsigned
I think the else is causing the problem.
There is no need to set the values of min & max to any magic number initially.
Just initialise them to zero, and the program will be fine.
It is a separate issue altogether if you want to test for overflow on a particular type.
Can you please use code tags in the future? The <> button on the right.