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


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Need some ideas on how to calculate this

  1. #1
    Member
    Join Date
    May 2011
    Location
    west palm beach, FL
    Posts
    189
    My Mood
    Tired
    Thanks
    41
    Thanked 11 Times in 10 Posts

    Default 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. #2
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    979
    Thanks
    7
    Thanked 206 Times in 182 Posts

    Default 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. #3
    Member
    Join Date
    May 2011
    Location
    west palm beach, FL
    Posts
    189
    My Mood
    Tired
    Thanks
    41
    Thanked 11 Times in 10 Posts

    Default 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. #4
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    979
    Thanks
    7
    Thanked 206 Times in 182 Posts

    Default Re: Need some ideas on how to calculate this

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

Similar Threads

  1. Any ideas?
    By ahender1 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 2nd, 2012, 03:58 PM
  2. Any Program Ideas?
    By Java Programmer in forum Java Theory & Questions
    Replies: 7
    Last Post: January 18th, 2012, 08:05 AM
  3. Cannot calculate. Please help me....
    By safarina02 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: September 15th, 2011, 02:11 PM
  4. Running out of ideas...
    By Cat in forum What's Wrong With My Code?
    Replies: 6
    Last Post: March 12th, 2011, 11:21 AM
  5. I need ideas on how to read this
    By thursgun in forum File I/O & Other I/O Streams
    Replies: 0
    Last Post: April 21st, 2010, 10:31 PM