+ 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) }
6 Respostas
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....
+ 1
Unfortunately, I did not understand what you meant. Please explain.
+ 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.
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..
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...
0
Thank you very much!