0

Kotlin Parking fee project

can anyone help me evaluate this code because I am having issues with test case 4 in the kotlin project. fun main(args: Array<String>) { var hours = readLine()!!.toInt() var total: Double = 0.0 val hourChecker: Int = hours / 24 if (hours < 0){ println("Wrong Input. Please try again!") } else{ if (hours >= 5 && hours < 24) { total += 5 hours -= 5 } if (hours >= 24) { total = (15 * hourChecker) + (hours - (24 * hourChecker)) * 0.5 println(total) } else if (hours < 24) { total = total + (0.5 * hours) println(total) } else { total = hours * 0.5 println(total) } } }

28th Jun 2021, 10:23 PM
Faruk Umar
Faruk Umar - avatar
4 Respuestas
+ 6
If hours < 5, total should be hours * 1.0 Also you need to change your else if condition else if (hours > 5 && hours < 24) { total = total + (0.5 * hours) println(total) } else { total = hours * 1.0 println(total) }
29th Jun 2021, 2:10 AM
Simba
Simba - avatar
+ 2
Copy this answer and please check and like thanks
14th Sep 2021, 8:00 AM
Brigido bergado jr
Brigido bergado jr - avatar
+ 1
fun main(args: Array<String>) { var hours = readLine()!!.toInt() var total: Double = 0.0 if (hours > 24) { total += 15 * (hours / 24) + 0.5 * (hours % 24) } else if(hours < 24 && hours > 5) { total += (hours - 5) * 0.5 + 5 } else { total += hours * 1 } println(total) }
14th Sep 2021, 8:00 AM
Brigido bergado jr
Brigido bergado jr - avatar
0
I will post my full code here, I hope it helps, let me know if you have questions: ====== 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:24 AM
Raed
Raed - avatar