0

Parking Fee (Problem with test 3-6)

Hidden test is fails, please tell me the reason. The task: You are making a car parking software that needs to calculate and output the amount due based on the number of hours the car was parked. The fee is calculated based on the following price structure: - the first 5 hours are billed at $1 per hour. - after that, each hour is billed at $0.5 per hour. - for each 24 hours, there is a flat fee of $15. My code: fun main(args: Array<String>) { var hours = readLine()!!.toInt() var total: Double = 0.0 var z = 0 if (hours>24) { z = hours - 24 println ((z*0.5)+15) } if (hours > 5 && hours < 24) { var hou = hours - 5 println(hou * 0.5 + 5) } }

13th Jul 2021, 9:50 AM
Всеволод Новиков
Всеволод Новиков - avatar
2 odpowiedzi
+ 4
This might help! fun main(args: Array<String>) { var hours = readLine()!!.toInt() // var total: Double = 0.0 var z:Int; if (hours>24) { z = hours%24 println ((z*0.5)+15*(hours-z)/24) } if (hours > 5 && hours < 24) { var hou = hours - 5 println(hou * 0.5 + 5) } if(hours<=5){ println(hours*1) } } You didn't checked for hours less than equal to 5 and for hours greater than equal to 48.
13th Jul 2021, 10:54 AM
Abhay
Abhay - avatar
0
fun main(args: Array<String>) { var hours = readLine()!!.toDouble() var total: Double = 0.0 val days: Double val remaining_hours: Double if (hours >= 24) { days = Math.floor(hours/24) remaining_hours=hours - (days*24) total= days*15 + (remaining_hours*.5) } else{ if (hours < 6){ total = hours } else{ total = 5+((hours-5)*.5) } } println(total) }
29th Mar 2022, 1:30 AM
Raed
Raed - avatar