+ 1

Parking fee - where the mistake is hidden?

Hi everyone! Could please someone help me with parking fee task? Why this code is incorrect? fun main(args: Array<String>) { var hours = readLine()!!.toInt() var total: Double = 0.0 var i = 8 if (hours <= 5) { total = hours * 1.0 } else if (hours < 24) { total = hours * 0.5 } else if (hours == 24) { total = 15.0 } else { total = 15.0 + (hours * 0.5) } println(total) } The task is the following: 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.

13th Mar 2022, 11:48 AM
Olesia
4 ответов
+ 3
You need to calculate the payment for each past day, that is, try to determine the payment for, for example, 50 hours
13th Mar 2022, 12:29 PM
Solo
Solo - avatar
+ 2
Pls post full description along with question.. I guess, if hour = 25 then it's one day + 1hr so output should be 15+(1*0.5) =15.5 But your output : 15+(25*0.5) = 27.5!!? hope it helps..
13th Mar 2022, 12:08 PM
Jayakrishna 🇮🇳
+ 2
Notify others after any update in question like this Olesia Its like : If hr is less than 5 then hr*1.0 If hr is greater than 5 but not past 24hr then it's 5 + (hr-5) *0.5 If it's greater than 24 hr then per each day + (raminging hr*05) Like : If hr = 4 => 4*1=4 If hr = 9 => 5 + 4*0.5= 7 If hr = 50 => 15*2 + 2*0.5=> 31 ( 2days + 2 hr).. try this way. hoping am not wrong.. because am not tested.. Hope it helps.
13th Mar 2022, 12:41 PM
Jayakrishna 🇮🇳
+ 2
Jayakrishna🇮🇳 and Solo thank you soo much for your help!
13th Mar 2022, 9:27 PM
Olesia