/*
    Limits to integers and illustration of overflow and underflow errors.
    
    1) Exercise try changing all int to "short int" or "long int".

    See Nyhoff P43-44.
*/

#include <iostream>     // cout
#include <limits>       // numeric_limits
using namespace std;

int main()         
{                  
   int maxvalue=numeric_limits<int>::max();
   int minvalue=numeric_limits<int>::min();

   cout << "minvalue=" << minvalue << endl;
   cout << "maxvalue=" << maxvalue << endl;

// Size of int variable
   cout << "Number of bytes=" << sizeof(int) << endl;
   cout << "Number of bits=" << 8*sizeof(int) << endl;
   
// Illustrating overflow errors:
// 1+maxvalue = minvalue
   int overmax=maxvalue+1;
   cout << "overmax=" << overmax << endl;

   int undermin=minvalue-1;
   cout << "undermin=" << undermin << endl;

   return 0;                        
}                                   
