Tthe parking fee quest | Sololearn: Learn to code for FREE!

+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?

8/22/2021 5:49:32 PM

Matteo Cervini

8 Answers

New Answer

+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.

+4

You have forgotten to put your code in the question. Now we can only guess.

+3

ok nothing,I fixed it by myself

+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.

+2

What is the meaning of fun tag πŸ”–

+1

Something you have written is too small code, you should add another 100 lines. πŸ˜ƒ

+1

Matteo Cervini πŸ‘πŸ‘πŸ‘ Congratulations, you have not come an easy way to defeat this mission. So what was the problem? Share your research.

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) } }