Cyclist

Report a typo

While training, a cyclist rides the same road to and from. Now his distance controller is not working: there is an error in the controller code, and the road back is calculated incorrectly.

The variable distance contains the last distance traveled in one direction. If the cyclist is riding back, the distance variable must be negative. To calculate the total distance traveled, the negative distance must be inverted and then added to the totalDistance variable. However, for some reason, the code does not work now.

Fix the code below to make it work.

Sample Input 1:

-10
30

Sample Output 1:

40
Write a program in Kotlin
fun main() {
var distance = readLine()!!.toInt() // the distance back
var totalDistance = readLine()!!.toInt()

// fix the code below
if (distance < 0) {
val distance = -distance
}
totalDistance += distance
println(totalDistance)
}
___

Create a free account to access the full topic