+ 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

31st May 2020, 5:14 PM
Irine Nabwire
Irine Nabwire - avatar
9 Réponses
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) }
31st May 2020, 5:20 PM
Irine Nabwire
Irine Nabwire - avatar
+ 2
I do not know much kotlin but this seems to be one easy way. https://code.sololearn.com/cScclYi8IoFq/?ref=app
31st May 2020, 5:59 PM
Avinesh
Avinesh - avatar
+ 2
Thanks alot
31st May 2020, 6:34 PM
Irine Nabwire
Irine Nabwire - avatar
+ 2
But you have forget to return?
31st May 2020, 6:37 PM
Irine Nabwire
Irine Nabwire - avatar
+ 1
Pls, show your solution to get help.
31st May 2020, 5:15 PM
ÍßĀŗľí‚ė¨Bad‚ė¨Boy‚ė¨ŗľíÍßā
ÍßĀŗľí‚ė¨Bad‚ė¨Boy‚ė¨ŗľíÍßā - avatar
+ 1
Yes
31st May 2020, 5:51 PM
Irine Nabwire
Irine Nabwire - avatar
0
Hello Irine Nabwire Please show us your attempt or describe where you have problems.
31st May 2020, 5:21 PM
Denise Roßberg
Denise Roßberg - avatar
0
Is there another way to tackle this question,I have tried but is not working
31st May 2020, 5:23 PM
Irine Nabwire
Irine Nabwire - avatar
0
Your code seems to work. I am not sure if I understand you. Do you want a different solution?
31st May 2020, 5:34 PM
Denise Roßberg
Denise Roßberg - avatar