Design a computer programming experiment in C++ to determine what happens when
a variable of type int is incremented above its range or decremented below its range. Repeat your experiment to determine what happens with a short int and long int. Next, modify your experiment to find out how unsigned variants of the integer types behave when their range is exceeded. Finally, try your experiment with a float and double.
I am trying to get the code to work but this is what I have and it wont work!
#include <iostream>
#include <limits>
using namespace std;
int main()
{
cout << "Minimum value for integer: "
<< numeric_limits<int>::min() << endl;
cout << "Decrementing the minimum value of integer below its range: ";
numeric_limits--;
cout << "Maximum value for integer: "
<< numeric_limits<int>::max() << endl;
cout << "Incrementing the maximum value of integer above its range: ";
numeric_limits++;
cout << endl;
cout << "Minimum value for short int: "
<< numeric_limits<short>::min() << endl;
cout << "Decrementing the minimum value of short int below its range: ";
numeric_limits--;
cout << "Maximum value for short int: "
<< numeric_limits<short>::max() << endl;
cout << "Incrementing the maximum value of short int above its range: ";
numeric_limits++;
cout << endl;
cout << "Minimum value for long int: "
<< numeric_limits<long>::min() << endl;
cout << "Decrementing the minimum value of long int below its range: ";
numeric_limits--;
cout << "Maximum value for long int: "
<< numeric_limits<long>::max() << endl;
cout << "Incrementing the maximum value of long int above its range: ";
numeric_limits++;
cout << endl;
cout << "Minimum value for unsigned int: "
<< numeric_limits<unsigned int>::min() << endl;
cout << "Decrementing the minimum value of unsigned int below its range: ";
numeric_limits--;
cout << "Maximum value for unsigned int: "
<< numeric_limits<unsigned int>::max() << endl;
cout << "Incrementing the maximum value of unsigned int above its range: ";
numeric_limits++;
cout << endl;
cout << "Minimum value for float: "
<< numeric_limits<float>::min() << endl;
cout << "Decrementing the minimum value of float below its range: ";
numeric_limits--;
cout << "Maximum value for float: "
<< numeric_limits<float>::max() << endl;
cout << "Incrementing the maximum value of float above its range: ";
numeric_limits++;
cout << endl;
cout << "Minimum value for double: "
<< numeric_limits<double>::min() << endl;
cout << "Decrementing the minimum value of double below its range: ";
numeric_limits--;
cout << "Maximum value for double: "
<< numeric_limits<double>::max() << endl;
cout << "Incrementing the maximum value of double above its range: ";
numeric_limits--;
numeric_limits is a class, not an object. Do this:
Go from this:
1 2 3 4
cout << "Minimum value for integer: "
<< numeric_limits<int>::min() << endl;
cout << "Decrementing the minimum value of integer below its range: ";
numeric_limits--;
To this:
1 2 3 4 5
int value = numeric_limits<int>::min();
cout << "Minimum value for integer: "
<< value << endl
<< "Decrementing the minimum value of integer below its range: "
<< --numeric_limits << endl;
#include <iostream>
#include <limits>
usingnamespace std;
int main()
{
#include <iostream>
#include <limits>
usingnamespace std;
int main()
{
cout << "Minimum value for integer: "
<< numeric_limits<int>::min() << endl;
cout << "Decrementing the minimum value of integer below its range: ";
numeric_limits--;
cout << "Maximum value for integer: "
<< numeric_limits<int>::max() << endl;
cout << "Incrementing the maximum value of integer above its range: ";
numeric_limits++;
cout << endl;
cout << "Minimum value for short int: "
<< numeric_limits<short>::min() << endl;
cout << "Decrementing the minimum value of short int below its range: ";
numeric_limits--;
cout << "Maximum value for short int: "
<< numeric_limits<short>::max() << endl;
cout << "Incrementing the maximum value of short int above its range: ";
numeric_limits++;
cout << endl;
cout << "Minimum value for long int: "
<< numeric_limits<long>::min() << endl;
cout << "Decrementing the minimum value of long int below its range: ";
numeric_limits--;
cout << "Maximum value for long int: "
<< numeric_limits<long>::max() << endl;
cout << "Incrementing the maximum value of long int above its range: ";
numeric_limits++;
cout << endl;
cout << "Minimum value for unsigned int: "
<< numeric_limits<unsignedint>::min() << endl;
cout << "Decrementing the minimum value of unsigned int below its range: ";
numeric_limits--;
cout << "Maximum value for unsigned int: "
<< numeric_limits<unsignedint>::max() << endl;
cout << "Incrementing the maximum value of unsigned int above its range: ";
numeric_limits++;
cout << endl;
cout << "Minimum value for float: "
<< numeric_limits<float>::min() << endl;
cout << "Decrementing the minimum value of float below its range: ";
numeric_limits--;
cout << "Maximum value for float: "
<< numeric_limits<float>::max() << endl;
cout << "Incrementing the maximum value of float above its range: ";
numeric_limits++;
cout << endl;
cout << "Minimum value for double: "
<< numeric_limits<double>::min() << endl;
cout << "Decrementing the minimum value of double below its range: ";
numeric_limits--;
cout << "Maximum value for double: "
<< numeric_limits<double>::max() << endl;
cout << "Incrementing the maximum value of double above its range: ";
numeric_limits--;
cout << endl;
return 0;
}
cout << "Maximum value for integer: "
<< numeric_limits<int>::max() << endl;
cout << "Incrementing the maximum value of integer above its range: ";
numeric_limits++;
cout << endl;
cout << "Minimum value for short int: "
<< numeric_limits<short>::min() << endl;
cout << "Decrementing the minimum value of short int below its range: ";
numeric_limits--;
cout << "Maximum value for short int: "
<< numeric_limits<short>::max() << endl;
cout << "Incrementing the maximum value of short int above its range: ";
numeric_limits++;
cout << endl;
cout << "Minimum value for long int: "
<< numeric_limits<long>::min() << endl;
cout << "Decrementing the minimum value of long int below its range: ";
numeric_limits--;
cout << "Maximum value for long int: "
<< numeric_limits<long>::max() << endl;
cout << "Incrementing the maximum value of long int above its range: ";
numeric_limits++;
cout << endl;
cout << "Minimum value for unsigned int: "
<< numeric_limits<unsignedint>::min() << endl;
cout << "Decrementing the minimum value of unsigned int below its range: ";
numeric_limits--;
cout << "Maximum value for unsigned int: "
<< numeric_limits<unsignedint>::max() << endl;
cout << "Incrementing the maximum value of unsigned int above its range: ";
numeric_limits++;
cout << endl;
cout << "Minimum value for float: "
<< numeric_limits<float>::min() << endl;
cout << "Decrementing the minimum value of float below its range: ";
numeric_limits--;
cout << "Maximum value for float: "
<< numeric_limits<float>::max() << endl;
cout << "Incrementing the maximum value of float above its range: ";
numeric_limits++;
cout << endl;
cout << "Minimum value for double: "
<< numeric_limits<double>::min() << endl;
cout << "Decrementing the minimum value of double below its range: ";
numeric_limits--;
cout << "Maximum value for double: "
<< numeric_limits<double>::max() << endl;
cout << "Incrementing the maximum value of double above its range: ";
numeric_limits--;
cout << endl;
return 0;
}