0

I am enjoying Kotlin, but this code is way off. What is wrong?

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. Sample Input: 8 Sample Output: 6.5 Explanation: The first 5 hours are billed at $1/hour, which results in $5. After that, the next 3 hours are billed at $0.5/hour = $1.5. So, the total would be $5+$1.5 = $6.5 My Trial: fun main(args: Array<String>) { var hours = readLine()!!.toInt() var total: Double = 0.0 var i = 1 while(i >= 5){ total += i i++ } println(total) } Output is 0.0 because I am missing something.

8th Mar 2023, 5:52 PM
The Tina Experience
The Tina Experience - avatar
3 Réponses
+ 5
It's printing default value 0.0. because your while loop condition never gonna true var i = 1 while i>=5 which is false loop body won't execute condition should be like this while i<=5
8th Mar 2023, 6:10 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 4
Thanks ASR. Plus, someone else had this same question. I found them and their tips. Thanks everyone.
8th Mar 2023, 6:28 PM
The Tina Experience
The Tina Experience - avatar
0
Also. I now have the solution.
8th Mar 2023, 6:29 PM
The Tina Experience
The Tina Experience - avatar