Calculating kills and deaths in a game I'm trying to make a program that calculates your k/d ratio (kill/death, which is used in FPS games to make people believe that it's skill), how many kills you need without dying once to reach a goalKD. It also has a part that calculates how many battles you need if you give the program your average battle kills and battle deaths.

Is there a efficient way to program it? Currently, the way I'm doing it is getting me into programmer-efficiency hell.

For i = 1 to 100000 {
    While GoalKD&gt;KDratio {
      Kills = BattleKills + Kill
      Deaths = BattleDeaths + Death
      KDratio = Kills / Deaths
      i++
  }
}


I'm programming this in SmallBasic because I'm most familiar with it, and I think it's easily readable. Also, if possible, don't give the answer right away; give me some hints for me to practice my mind. Add the answer in a spoiler box.
For the kills needed part, you are trying to solve this equation:

k{current} + n
--------------  = r
  d{current}


Where r is the target rate and n is the number you're looking for. Some basic algebra:

n = rd - k


For the battles part, you need to solve

k{current} + b * k{battle}            // current kills + additional kills
--------------------------  = r
d{current} + b * d{battle}            // current deaths + additional deaths

k{current} + b * k{battle} = r * (d{current} + b * d{battle})  // multiply both sides by d{current} + b * d{battle}

k{current} + b * k{battle} = r * d{current} + r * b * d{battle})  // just showing multiplication of r

b * (k{battle} - r * d{battle}) = r * d{current} - k{current}  // subtracting terms from each side

     r * d{current} - k{current}
b =  ---------------------------  // dividing by k{battle} - r * d{battle}
     k{battle} - r * d{battle}


In your code above, this becomes

need = Math.ceiling( GoalKD * Deaths - Kills )
battles = Math.ceiling( ( GoalKD * Deaths - Kills ) / (BattleKills - GoalKD * BattleDeaths) )


[I'm not a SmallBasic guy, so please forgive any syntax errors above.]

(Edited to fix math error re battles required and add comments to the math.)