# Need some ideas on how to calculate this

• July 1st, 2012, 11:12 PM
derekxec
Need some ideas on how to calculate this
Hi i am making a calculator for a game i play but i cant figure out how to calculate it down to what i need

i have 2 text fields (troop number) and i put in a number say 1 into the first and 5 into the second text field(time reducer). 1 troop takes 5400 seconds so i times the number of troops by 5400 and that gives me the time and each time reducer reduces that time by 30% so if i have 1 it does 5400 - 30% then takes that total and minuses it by 30% etc 5 times

what i cant figure out is how i can make it get the total of the first -30% and then -30% from that total then take that total and minus it by 30%

i tried a while loop but this doesn't work

Code :

```while (timeReducer > 0) totalTime = trooptime * 0.7; timeReducer--;```

because it loops around and does the trooptime again instead of using the total time in the next calculation.....any ideas how i could make it so i could use the totaltime on the second calculation instead of the trooptime?

thanks for any advice you can give
• July 2nd, 2012, 12:31 AM
pbrockway2
Re: Need some ideas on how to calculate this
Start by assigning totalTime the value of trooptime then begin the while loop. In that loop you say totalTime=totalTime*0.7 (which is often written totalTime*=0.7). Notice how this doesn't reuse trooptime so the old value won't get in the way.

If your intention is to update the troop time, do that after the loop has finished doing the calculation.

To avoid embarassement, don't forget your braces! :)
• July 2nd, 2012, 06:09 AM
derekxec
Re: Need some ideas on how to calculate this
wow thanks a lot! that works perfectly...i was trying while loops for loops do while lol and couldnt figure thank you so much :D
• July 2nd, 2012, 06:50 PM
pbrockway2
Re: Need some ideas on how to calculate this
You're welcome, I'm glad you've got it sorted out.