Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![abdirahman liban](https://secure.gravatar.com/avatar/c1a3f1a7bd1c48053d30ff5821ce760e?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
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](https://secure.gravatar.com/avatar/54c2cac346df05d7b70cc0a6825c1cba?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Greg Kaleka
39,021 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](https://secure.gravatar.com/avatar/8d36cc5aed706061021be7cbd92078c9?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Cindy Lea
Courses Plus Student 6,497 PointsTry doing it the long way to see if it works: total = total + numbers
![abdirahman liban](https://secure.gravatar.com/avatar/c1a3f1a7bd1c48053d30ff5821ce760e?s=60&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
abdirahman liban
Courses Plus Student 2,163 Pointsit show me error : cannot convert value of type '[Double]' to expected argument type 'Double'
![Greg Kaleka](https://secure.gravatar.com/avatar/54c2cac346df05d7b70cc0a6825c1cba?s=60&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Greg Kaleka
39,021 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](https://secure.gravatar.com/avatar/8d36cc5aed706061021be7cbd92078c9?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Cindy Lea
Courses Plus Student 6,497 PointsTry this:
total += Double(numbers)
![abdirahman liban](https://secure.gravatar.com/avatar/c1a3f1a7bd1c48053d30ff5821ce760e?s=60&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
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