NEED HELP MY CODE WONT WORK!

Why wont my program work?

Can someone tell me what I did wrong?

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--;

cout << endl;

return 0;
}
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;
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#include <iostream>
#include <limits>

using namespace std;

int main()
{

#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--;

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<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--;

cout << endl;

return 0;
}
Topic archived. No new replies allowed.