Who knows to solve a parking fee with kotlin? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Who knows to solve a parking fee with kotlin?

9th Jul 2021, 11:03 PM
Solo Lord
Solo Lord - avatar
7 Answers
+ 12
From my experience if something (project) is hard to solve I search it at code section it gives me enough knowledge with clear under
11th Jul 2021, 6:24 PM
Jano c͓̽o͓̽d͓̽e͓̽r͓̽
Jano c͓̽o͓̽d͓̽e͓̽r͓̽ - avatar
+ 2
You need to multiply total by 1.0 since its datatype is double. Also check this post https://www.sololearn.com/Discuss/2771278/?ref=app fun main(args: Array<String>) { var hours = readLine()!!.toInt() var total: Double = 0.0 if(hours<=5){ total= hours*1.0 println(total) } else if(hours>5 && hours<24){ total= 5+(0.5*(hours-5)) println(total) } else if(hours==24){ total= 15.0 println(total) } else{ total= hours/24*15+(0.5*(hours%24)) println(total) } }
10th Jul 2021, 1:03 AM
Simba
Simba - avatar
+ 1
thanks bro it works
10th Jul 2021, 4:50 AM
Solo Lord
Solo Lord - avatar
+ 1
Also, if you do not want the initializer of the 'total' variable to be redundant, do not assign a value during its initialization. var total: Double str.6 total = hours.toDouble() str.9 not ' { ' str.14 total = 15.0 str.18 bug
10th Jul 2021, 9:10 AM
Solo
Solo - avatar
0
what exactly is not clear to you when solving this task?
9th Jul 2021, 11:23 PM
Solo
Solo - avatar
0
fun main(args: Array<String>) { var hours = readLine()!!.toInt() var total: Double = 0.0 if(hours<=5){ total= hours*1 println(total) } else if(hours>5 && hours<24) total= 5+(0.5*(hours-5)) println(total) } else if(hours==24){ total= 15 println(total) } else{ total= 15+(0.5*(hours-24)) println(total) } }
9th Jul 2021, 11:24 PM
Solo Lord
Solo Lord - avatar
0
fun main(args: Array<String>) { var hours = readLine()!!.toInt() var total: Double = 0.0 if (hours > 24) { while (hours >= 24) { total += 15 hours -= 24 } } else { var i = 1 while (i <= 5 && hours > 0) { total += 1 i++ hours-- } } total += hours * 0.5 println(total) }
27th Nov 2021, 9:17 PM
Dave