+ 1

Could you help me with this code?

fun main(args: Array<String>) { var hours = readLine()!!.toInt() var total: Double = 0.0 for(i in 1..hours){ if(i>5&&i<24){ total+=0.5 } else if(i<=5){ total+=1.0} else if(i==24){ total+=15.0 } else if(i>24){ total+=(i-24)*0.5 } } println(total)}

30th Jan 2022, 5:54 AM
Killiam Chances
Killiam Chances - avatar
3 odpowiedzi
+ 2
Hello, Your code compiles and runs. Can you describe your problem? Also please save your code in the playground and insert a link.
30th Jan 2022, 6:02 AM
Tibor Santa
Tibor Santa - avatar
+ 1
Ok I got it thank you for your answer
30th Jan 2022, 1:37 PM
Killiam Chances
Killiam Chances - avatar
0
According to the task description in the "Parking Fee" code project of Kotlin lesson 17 If the time exceeds 24 hours, then the total fee is 15 for every whole day, plus 0.5 for each additional hour. Your calculation does not reflect this case correctly.
30th Jan 2022, 1:30 PM
Tibor Santa
Tibor Santa - avatar