+ 1
Given a list of people’s heights in metres. Write a function that returns the average height and the total height
Need help in this question
9 odpowiedzi
0
fun main(args: Array<String>) {
var height= listOf(45.7,36.5,18.9,34.1,96.9,79.1)
var (avg,totalheight) = averageAndHeight(height)
println("Average Height: $avg .. totalSumHeights : $totalheight")
}
data class AverageMeasurements(var height: Double, var totalheight: Double)
fun averageAndHeight(height: Collection<Double>): AverageMeasurements {
var avg=height.average()
var totalheight=height.sum()
return AverageMeasurements(avg, totalheight)
}
+ 2
I do not know much kotlin but this seems to be one easy way.
https://code.sololearn.com/cScclYi8IoFq/?ref=app
+ 2
Thanks alot
+ 2
But you have forget to return?
+ 1
Pls, show your solution to get help.
+ 1
Yes
0
Hello Irine Nabwire
Please show us your attempt or describe where you have problems.
0
Is there another way to tackle this question,I have tried but is not working
0
Your code seems to work. I am not sure if I understand you. Do you want a different solution?