Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

abdirahman liban
Courses Plus Student 2,163 PointsVariadic Parameters
I wrote this code in xcode :
func mean (numbers:Double...)-> Double {
var total : Double = 0
for number in numbers {
total += numbers
}
return total / Double(numbers.count)
}
but is show me this error : binary operator "+=" cannot be applied to operands of type double and double
3 Answers

Greg Kaleka
39,018 PointsCareful with that error message - I imagine it's actually telling you it can't apply += to operands of type Double
and [Double]
, because you're trying to add the whole numbers
array!
You want total += number
, not total += numbers
.

Cindy Lea
Courses Plus Student 6,485 PointsTry doing it the long way to see if it works: total = total + numbers

abdirahman liban
Courses Plus Student 2,163 Pointsit show me error : cannot convert value of type '[Double]' to expected argument type 'Double'

Greg Kaleka
39,018 PointsYep - that error is telling you exactly what you need to know. You can't convert an array of Doubles into a Double. That's what [Double] is - an array of Doubles.

Cindy Lea
Courses Plus Student 6,485 PointsTry this:
total += Double(numbers)

abdirahman liban
Courses Plus Student 2,163 Pointsit show me error : cannot invoke intializer for type 'Double' for type 'Double ' with an argument list of '((Double))'
abdirahman liban
Courses Plus Student 2,163 Pointsabdirahman liban
Courses Plus Student 2,163 Pointsthank you