Hey guys I have a problem in parking fee problem of Kotlin | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Hey guys I have a problem in parking fee problem of Kotlin

all the test is working except test 4, please if anyone solved the problem before share your code.

30th Nov 2021, 7:26 PM
Ali Mahdi
Ali Mahdi - avatar
5 Answers
+ 2
Seyyed Ali Mahdi The output is expected to be float so the problem is your first if where you test hours <= 5 and then print hours which is an int. Try println(hours * 1.0)
30th Nov 2021, 8:01 PM
Paul K Sadler
Paul K Sadler - avatar
+ 3
First share your attempt so we can help you debug the code.
30th Nov 2021, 7:32 PM
Paul K Sadler
Paul K Sadler - avatar
+ 3
fun main(args: Array<String>) { var hours = readLine()!!.toInt() var total: Double = 0.0 var day = 0 if(hours <= 5){ println(hours) }else if(hours > 5 && hours<24){ println(5 + (hours-5)*.5) }else if(hours == 24){ println(15) }else { var d = hours / 24 day = d.toInt(); var x = day*15 println((x)+((hours - day*24)*.5) ) } }
30th Nov 2021, 7:38 PM
Ali Mahdi
Ali Mahdi - avatar
+ 3
It worked thanks❤
30th Nov 2021, 8:52 PM
Ali Mahdi
Ali Mahdi - avatar
+ 2
You're welcome.
30th Nov 2021, 8:54 PM
Paul K Sadler
Paul K Sadler - avatar