Advertisement

increasing variable

Started by February 23, 2000 07:08 PM
2 comments, last by ViPeR007 24 years, 6 months ago
This may seem a pretty basic question but how could you detect if a variable was increasing/descreasing? Its not if (variable++) is it? Thanx, ViPeR
The easiest way I can think of would be to have another variable which is initilised with the origonal value of the other variable and compare their values periodically.

eg.
if (num1 != num2)
{
/* do whatever
}
Advertisement
variables don''t just increase and decrease on their own. You have to do that for them, so the logical thing would be to have a variable that represents it''s last value
old_y = y;
y++;

or to have a variable that represents it''s change
dy = -5;
y += dy;

quote: Original post by Jim_Ross

...
old_y = y;
y++;
...


Unless I am very mixed up you could also do this as:

old_y = y++;

Because the postfix operator was used, the origional value of y is returned with y being incremented. This is one feature of C++ I love, so I thought I would point it out


--------------------

"Very funny Scottie, now beam down my clothes."
www.trak.to/rdp

Yanroy@usa.com

--------------------

You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming
You are unique. Just like everybody else.
"Mechanical engineers design weapons; civil engineers design targets."
"Sensitivity is adjustable, so you can set it to detect elephants and other small creatures." -- Product Description for a vibration sensor

Yanroy@usa.com

This topic is closed to new replies.

Advertisement