0

Could anyone please help me solving the below code written in Kotlin? Thank you

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. This means, that, for example, if a car parked for 26 hours, the bill should be 15+(2*0.5) = 16.0, because it was parked for 24 hours plus 2 additional hours. The output should be a Double even if the amount is a round number. // My code // fun main(args: Array<String>) { var hours = readLine()!!.toInt() var total: Double = 0.0 if(hours <=5){ println(hours*1.0)} else if(hours<=23){ println((hours-5)*0.5 + 5) } else if (hours >=24){ println (15+(hours-24)*0.5) } else { println ("invalid input") } }

17th Jul 2021, 10:57 AM
Ehthisham Mohammed
Ehthisham Mohammed - avatar
2 odpowiedzi
+ 4
else if (hours >=24){ println (hours/24*15+(hours%24)*0.5) } https://www.sololearn.com/discuss/2771278/?ref=app
17th Jul 2021, 11:03 AM
Simba
Simba - avatar
+ 1
Thank you so much, Simba. It's complete now
17th Jul 2021, 12:05 PM
Ehthisham Mohammed
Ehthisham Mohammed - avatar