+ 2
Can anyone help me to correct my mistakes?
fun main(args: Array<String>) { var hours = readLine()!!.toInt() var total: Double = 0.0 var d=hours-5; var g=hours-24; if(hours>24){ var f=15+(0.5*g) ; println(f); } else{ var f=5+(0.5*d) ; println(f); } }
4 Respuestas
+ 4
Did you notice that your variable d become <0 if hours <5?
Try using an else if statement to avoid it.
Also, if hours is 49. It should be 15 * 2 + 1* 0.5 = 30.5, not 15 + 25 * 0.5 = 27.5
(© CarrieForle)
+ 3
Because 49= 24*2+1
It's mentioned in the task
"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."
+ 3
Atul
I noted that when I input 24, the output is 14.5, not 15.
I would suggest the following.
if >= 1day
Use /24 to ascertain the number of days from hours, and charge 15 per day.
Use %24 to ascertain the extra hours & charge 0.5 per hour
else < 1day
Your existing code deals well with this already.
Allow for parking of less than 5 hrs
Your coding is good, just the logic needs to be tweaked
+ 1
Why will 1 be again multiplied ?