0

What is wrong in code

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.

27th Feb 2021, 6:02 PM
Pranay Sehgal
Pranay Sehgal - avatar
7 Answers
+ 8
This is my code that pass all tests. Please check it . fun main(args: Array<String>) { var hours = readLine()!!.toInt() var total: Double = 0.0 if(hours <= 0) total = 0.0; else if(hours <= 5) total = hours * 1.0 else if(hours > 5 && hours < 24) total = 5 + ((hours - 5) * 0.5) else if(hours == 24) total = 15.0 else if(hours > 24) total = ((hours / 24) * 15) + ((hours % 24) * 0.5); print(total) }
1st Mar 2021, 11:54 AM
Wei Phyo Aung
Wei Phyo Aung - avatar
+ 3
Answer: You need to check only two conditions and one else. Pseudo Code: - if its greater than 24 hours total += 15 * (hours / 24) + 0.5 * (hours % 24) - if its less than 24 and greater than 5 total += (hours - 5) * 0.5 + 5 - else total += hours * 1 ps~ its simple you just made it complicated will dm you the code if you want but try it on your own first
27th Feb 2021, 6:15 PM
Sharique Khan
Sharique Khan - avatar
+ 1
Wei Phyo Aung We should never post direct answer. Give him hints, pseudo code or try correcting his existing code.
1st Mar 2021, 11:59 AM
Sharique Khan
Sharique Khan - avatar
+ 1
Samee I write the same code as yours still cant find problem pls helppp
16th Jul 2022, 7:23 PM
Gurmeet Kukreja
0
This is my code
27th Feb 2021, 6:02 PM
Pranay Sehgal
Pranay Sehgal - avatar
0
fun main(args: Array<String>) { var hours = readLine()!!.toInt() var a: Double = 0.0 if(hours == 5) { println("$5") } else if(hours > 5 && hours < 24 ){ var a = hours - 5; print(a * 0.5 + 5) } else if(hours == 24){ println("15") } else if(hours > 24){ var a = hours - 24 println(a * 0.5 + 15) } else { var a = hours - 24; println(a * 0.5 + 15) } }
27th Feb 2021, 6:03 PM
Pranay Sehgal
Pranay Sehgal - avatar
0
Thanks all of my friends for solving this question
1st Mar 2021, 1:39 PM
Pranay Sehgal
Pranay Sehgal - avatar