I do not know why the test four of my Parking fee program is not running. Can I get a hand please?! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

I do not know why the test four of my Parking fee program is not running. Can I get a hand please?!

fun main(args: Array<String>){ var hours = readLine()!!.toInt() var total: Double=0.0 val differenceOne=(hours-24) val differenceTwo=(hours-5) val flatfee=15 val mod=hours-(hours%24) val divid=mod/24 val differenceThree=(hours%24) if (hours==1 && hours<=5){ println(hours*1) } else if(hours%24==0){ println(flatfee*divid) } else if(hours>=5 && hours<24){ print(5+(differenceTwo*0.5)) } else if(hours>24 && hours<48){ println((flatfee)+(differenceOne*0.5)) } else if(hours>24 && hours%24!=0){ println((flatfee*divid)+(differenceThree*0.5)) } else{ println(hours) } }

15th Jan 2022, 11:55 AM
♥«|₹∆¢|·|£∆L»♥
♥«|₹∆¢|·|£∆L»♥ - avatar
6 Answers
+ 6
if (hours >=1 && hours<=5){ println(hours*1.0) }
15th Jan 2022, 12:02 PM
Simba
Simba - avatar
+ 1
Actually you're right. Thanks.
15th Jan 2022, 12:11 PM
♥«|₹∆¢|·|£∆L»♥
♥«|₹∆¢|·|£∆L»♥ - avatar
+ 1
Thanks Rachael Loveth, i’m gonna upgrade my code
16th Jan 2022, 2:07 AM
MIKEY
MIKEY - avatar
0
Still the same thing.
15th Jan 2022, 12:09 PM
♥«|₹∆¢|·|£∆L»♥
♥«|₹∆¢|·|£∆L»♥ - avatar
0
fun main(args: Array<String>) { var hours = readLine()!!.toInt() var total: Double = 0.0 if(hours in 0..5){ total=hours*1.0 } else if(hours in 6 until 24){ total=5.0+((hours-5.0)*0.5) } else if(hours>24){ val x=hours/24 total=(15.0*x)+(hours-(x*24))*0.5 } else{ total=0.0 } println(total) }
15th Jan 2022, 12:57 PM
MIKEY
MIKEY - avatar
0
Rachael Loveth Alex Ivan Only as a hint: Keep in mind that you also can use a simple "when" statement. And you can print the result directly. There is no need for any additionel variable. With some more experience you will do it like this: fun main(args: Array<String>) { var h = readLine()!!.toInt() println ( when { h < 6 -> h*1.0 h < 24 -> 5+(h-5)*0.5 else -> 15*(h/24) + 0.5*(h%24) } ) }
15th Jan 2022, 1:31 PM
Coding Cat
Coding Cat - avatar