"Protecting" variable values..
Posted on 2011-03-25
I have read some initial values from a file, and put these values into variables.
All values in the file are positive (greater than zero).
int Value1 = 5 (read from file)
int Value2 = 3 (read from file)
int Value3 = 4 (read from file)
I want to be able to add or subtract values from these initial values (subtract with 1 or add with 1), but when the value reaches zero (NULL) or exceeds the value read from file the add/subtract operation should be aborted (or stopped).
One way of doing this is (of course) to have another set of values called InitValue1, initValue2 and InitValue3, put the initial values in each of them and then compare each of them for each add/subtract operation.
// Read from file -> InitValue1, initValue2, initValue3;
Value1 = initValue1;
value2 = initValue2;
value3 = initValue3;
if (Value1++) > initValue1 -> Abort operation
if (Value1--) = 0 -> Abort operation
Are there some intrinsic functions or other "smart" ways to achieve this goal in Visual C++ 2003 ?