0
Who knows to solve a parking fee with kotlin?
7 Antworten
+ 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
+ 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)
}
}
+ 1
thanks bro it works
+ 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
0
what exactly is not clear to you when solving this task?
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)
}
}
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)
}