+ 1

Problem In Parking Fee

Hello, I need serious help. I wrote a code in the parking fee section of kotlin language but it does not accept me, please help me. fun main(args: Array<String>) { var hours = readLine()!!.toInt() var total: Double = 0.0 if (hours <= 5) { total = hours.toDouble() }else if (hours > 5 && hours < 24) { total = ((hours - 5) * 0.5) + 5 }else { total = (((hours / 24) - ((hours % 24)/24)) * 15 + (hours % 24)).toDouble() } println(total) }

13th Apr 2022, 8:17 PM
gholamhasanEhsani 🇮🇷
gholamhasanEhsani 🇮🇷 - avatar
6 ответов
0
oh. sry, not saw it. may be too late? Use this : else if(hours >= 24){ total = (hours / 24) * 15 + (hours % 24) * 0.5 hope it helps....
17th Apr 2022, 10:57 AM
Jayakrishna 🇮🇳
+ 1
Unfortunately, I did not understand what you meant. Please explain.
15th Apr 2022, 8:21 AM
gholamhasanEhsani 🇮🇷
gholamhasanEhsani 🇮🇷 - avatar
+ 1
my updated code is: fun main(args: Array<String>) { var hours = readLine()!!.toInt() var total: Double = 0.0 if (hours <= 5.0) { total = hours.toDouble() }else if (hours > 5.0 && hours < 24.0) { total = (((hours - 5.0) * 0.5) + 5.0).toDouble() }else if(hours >= 24){ total = (((hours / 24).toInt()) * 15) + ((hours - 24.0) * 0.5)).toDouble()) } println(total.toDouble()) } and I followed your tips.
15th Apr 2022, 9:20 AM
gholamhasanEhsani 🇮🇷
gholamhasanEhsani 🇮🇷 - avatar
0
If it's greater than 24 hr then => per each day + (raminging hr*05) If hr = 50 => 15*2 + 2*0.5=> 31 ( its 2days + 2 hr) https://www.sololearn.com/discuss/2999649/?ref=app hope it helps..
13th Apr 2022, 8:20 PM
Jayakrishna 🇮🇳
0
If input is greater than 24 hour then => calculate per each day charge + (raminging hr*05) Ex: If hr = 50 => it's 2 days + 2 hour so charge is : 15*2 + 2*0.5=> 31 is fee.. Hope it's clear now...
15th Apr 2022, 8:39 AM
Jayakrishna 🇮🇳
0
Thank you very much!
25th Apr 2022, 8:19 PM
gholamhasanEhsani 🇮🇷
gholamhasanEhsani 🇮🇷 - avatar