+ 1
My code has errors. This looks right to me, though. What is wrong?
Each day a family consumes 15 liters of water. Given the number of years as input, you need to calculate and output the amount of water consumed in that period. Sample Input 5 Sample Output 27375 The water consumption in 5 years would be: 5*365*15 = 27375 Wrong Solution=> fun main(args: Array<String>) { var years = readLine()!!.toInt() var liters = readLine()!!.toInt() var days =readLine()!!.toInt() println(years * days * liters) }
8 odpowiedzi
+ 5
Seems to me the task only requires us to read one input - number of years. Neither number of liter per day nor days per year needs to be read in.
So try make <days> and <liters> constant values to be used in calculation, or just use integer literal in their place.
+ 3
Praveen Kumar please delete your offensive comment.
+ 3
Awesome work matey!
Glad you got there. You were on the right path, just as you said, you made it too hard on yourself.
Happy coding!
+ 2
Thanks Ipang
+ 2
I finally did it you guys. Before, I was way out in left field over complicating things. Here is the answer:
fun main(args: Array<String>) {
var years = readLine()!!.toInt()
val days = 365
val liters = 15
println(years * days * liters)
}
+ 1
Thanks Ausgrindtube. I just ignored that guy. We are all here to learn.
+ 1
Thanks guys!