Generation

generate functionSat, 12 Nov 2022

a elaborated function to handle the points gotten by an unknown player that does a hit on a darts board, the hit must be equal to a previously defined target (that goes from 1 to 100), the closer the hit is to the target, the more points the player receives in exchange

fun pointsForHit(hit: Int, target: Int): Int { val diff = abs(hit - target) return 100 - diff } fun main(args: Array<String>) { val hit = 40 val target = 50 val points = pointsForHit(hit, target) println("hit: $hit, target: $target points: $points") }

Questions about programming?Chat with your personal AI assistant