exceed.cpp 1.1 KB

1234567891011121314151617181920212223242526272829
  1. // exceed.cpp -- exceeding some integer limits
  2. #include <iostream>
  3. #define ZERO 0 // makes ZERO symbol for 0 value
  4. #include <climits> // defines INT_MAX as largest int value
  5. int main()
  6. {
  7. using namespace std;
  8. short sam = SHRT_MAX; // initialize a variable to max value
  9. unsigned short sue = sam;// okay if variable sam already defined
  10. cout << "Sam has " << sam << " dollars and Sue has " << sue;
  11. cout << " dollars deposited." << endl
  12. << "Add $1 to each account." << endl << "Now ";
  13. sam = sam + 1;
  14. sue = sue + 1;
  15. cout << "Sam has " << sam << " dollars and Sue has " << sue;
  16. cout << " dollars deposited.\nPoor Sam!" << endl;
  17. sam = ZERO;
  18. sue = ZERO;
  19. cout << "Sam has " << sam << " dollars and Sue has " << sue;
  20. cout << " dollars deposited." << endl;
  21. cout << "Take $1 from each account." << endl << "Now ";
  22. sam = sam - 1;
  23. sue = sue - 1;
  24. cout << "Sam has " << sam << " dollars and Sue has " << sue;
  25. cout << " dollars deposited." << endl << "Lucky Sue!" << endl;
  26. // cin.get();
  27. return 0;
  28. }