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.
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)
}
+ 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
+ 1
Wei Phyo Aung
We should never post direct answer. Give him hints, pseudo code or try correcting his existing code.
+ 1
Samee I write the same code as yours still cant find problem pls helppp
0
This is my code
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)
}
}
0
Thanks all of my friends for solving this question