+ 2

Tthe parking fee quest

I'm trying to do the parking fee quest in kotlin. on 6 case, 5 work and one not, the fourth. I have considered a various of possibilities. If u stay at least 5 or less hours, more than 5, a day, days, a day plus hours or days plus hours. What have I been missed?

22nd Aug 2021, 5:49 PM
Matteo Cervini
Matteo Cervini - avatar
8 Antworten
+ 4
Tell me what this loop does here: for (hours in 1..5)? ☺️ You declared a new variable inside the loop with the same name as the external variable "hours", although Kotlin will "swear", it will execute the loop, but JAVA will stop the program and give an error. In any case, this is a very bad practice for you, you need to learn to write the codes correctly from the beginning, so think about whether this loop is needed here and if so, then fix at least that. Also, you still have a lot of unnecessary things and there are similar inconsistencies. Happy coding.
22nd Aug 2021, 8:28 PM
Solo
Solo - avatar
+ 4
You have forgotten to put your code in the question. Now we can only guess.
22nd Aug 2021, 6:06 PM
Paul
Paul - avatar
+ 3
ok nothing,I fixed it by myself
22nd Aug 2021, 6:56 PM
Matteo Cervini
Matteo Cervini - avatar
+ 2
in this linses: if(hours <= 5){ for(hours in 1..5) total += 1 println(total) } I forgot to modify it, couse i did copy and past from the liens below and i dint canceled the for.
22nd Aug 2021, 7:18 PM
Matteo Cervini
Matteo Cervini - avatar
+ 2
What is the meaning of fun tag 🔖
24th Aug 2021, 3:04 AM
Shubham Bhatia
Shubham Bhatia - avatar
+ 1
Something you have written is too small code, you should add another 100 lines. 😃
22nd Aug 2021, 6:37 PM
Solo
Solo - avatar
+ 1
Matteo Cervini 👏👏👏 Congratulations, you have not come an easy way to defeat this mission. So what was the problem? Share your research.
22nd Aug 2021, 7:14 PM
Solo
Solo - avatar
0
you are right. here u are the code: fun main(args: Array<String>) { var hours = readLine()!!.toInt() var total: Double = 0.0 var total1: Double = 0.0 var total2: Double = 0.0 var x = 0 val flat_fee: Double = 15.0 if(hours <= 5){ for(hours in 1..5) total += 1 println(total) } else if(hours < 24){ for(hours in 1..5) total1 += 1 hours -= 5 total2 = hours * 0.5 total = total1 + total2 println(total) } else if(hours == 24){ total = flat_fee println(total) } else if(hours % 24 == 0){ x = hours / 24 total = flat_fee * x println(total) } else if(hours > 48){ x = hours / 24 total1 = flat_fee * x hours = hours - (x * 24) total2 = hours * 0.5 total = total1 + total2 println(total) } else if(hours > 24){ total1 = flat_fee hours -= 24 total2 = hours * 0.5 total = total1 + total2 println(total) } }
22nd Aug 2021, 6:13 PM
Matteo Cervini
Matteo Cervini - avatar