+ 1

What's wrong with this code?

fun main(args: Array<String>) { var hours = readLine()!!.toInt() var total: Double = 0.0 if(hours>5 && hours<24){ total += (5+((hours-5)*.5)) } else if(hours>=24){ total += (15+((hours-24)*.5)) } else{ total += hours } println(total) }

22nd Jan 2022, 10:12 AM
Annesh Lobdha Singh
Annesh Lobdha Singh - avatar
3 Answers
+ 2
If this is the "Parking Fee" code coach in Kotlin, well this is not an easy one. I won't give you a straight solution, but others will do đŸ˜…đŸ˜‚đŸ€Ł and you won't understand anything. What I can tell you is to be more careful at the second else if. Also, you can use "when" keyword. total = when { hours <= 5 -> hours * 1.0; hours <= 24 && hours > 5 -> ... else -> ... } Good luck!
22nd Jan 2022, 10:28 AM
Romeo Cojocaru
Romeo Cojocaru - avatar
+ 2
Ancient Lynx See?! If all the SoloLearn users would understand that giving right away the solution and not a small or a big hint is not the way of becoming a better programmer, than this community will be great.
22nd Jan 2022, 11:43 AM
Romeo Cojocaru
Romeo Cojocaru - avatar
+ 1
Thanks Romeo Cojocaru ... Your suggestion helped me a lot and I got the answer !! You are great !
22nd Jan 2022, 11:37 AM
Annesh Lobdha Singh
Annesh Lobdha Singh - avatar