0

Why it is failing the test cases?

fun main(args: Array<String>) { var hours = readLine()!!.toInt() var total: Double = 0.0 if(hours<5) total =hours*1.00 else if(hours>=5 && hours<=23) total=5.00+(hours-5)*0.5 else if(hours>=24) total=15.00+(hours-24)*0.5 print(total) }

27th Jun 2021, 3:49 PM
Atul
Atul - avatar
4 Respuestas
+ 2
Atul Because for each day there is 15$ and for each hours there is 0.5$ So if there is 30 hours then 30 / 24 will give 1 day and 30 % 24 will give 6 hours so total is 1 days and 6 hours total = 15 * 1 + 0.5 * 6 Another example: Suppose there is 50 hours so there would be 50 / 24 = 2 days and 50 % 24 = 2 hours so total is 2 days 2 hours total = 2 * 15 + 2 * 0.5
28th Jun 2021, 1:46 AM
A͢J
A͢J - avatar
+ 1
Atul Hours maybe more than 48 so your condition should be like this: if (hours > 24) { total = 15.0 * (hours / 24) + 0.5 * (hours % 24) }
27th Jun 2021, 3:59 PM
A͢J
A͢J - avatar
28th Jun 2021, 5:29 AM
Atul
Atul - avatar
0
🅰🅹 🅐🅝🅐🅝🅣 why hours/24 is done?
28th Jun 2021, 1:37 AM
Atul
Atul - avatar