Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

# Thread: Need some ideas on how to calculate this

1. ## 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

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

2. ## 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!

3. ## The Following User Says Thank You to pbrockway2 For This Useful Post:

derekxec (July 2nd, 2012)

4. ## 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

5. ## Re: Need some ideas on how to calculate this

You're welcome, I'm glad you've got it sorted out.