Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Reduce to zero
Message
From
05/02/2009 12:12:03
 
 
To
05/02/2009 11:19:27
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Environment versions
Visual FoxPro:
VFP 9 SP2
Miscellaneous
Thread ID:
01379529
Message ID:
01379538
Views:
24
>Here is probably a simple math problem but I seem to have a mental block:
>
>I want to reduce any given number to zero in 10 steps or loops. In each loop iteration I only have access to the previous value, not the initial starting value. I was thinking of subtracting a percentage off the previous value but that will not reduce to zero in 10 steps especially given that the number can have up to 4 decimals. Any obvious solution?
>
>Update: I also cannot know what iteration I am on. In other words, I want to reduce a number by some formula and know that within +/-10 iterations the number will fall to zero.

Dunno Jos, but wouldn't the step value be (InitialValue / 10) ?

If the number is not 'easily' divided by 10, ie (InitialValue / 10) * 10 != InitialValue, you could always populate a Collection with the first 9 values and the tenth value would be InitialValue - first 9 stepvalues

I would go for the collection approach regardless. You feed the collection and loop - removing one item at a time - until it's empty
Gregory
Previous
Reply
Map
View

Click here to load this message in the networking platform