Swift 编译报错:Binary operator '+=' cannot be applied to operands of type 'Double' and '[Double]'
funcarithmeticMean(numbers:Double...)->Double{vartotal:Double=0fornumberinnumbers{tot...
func arithmeticMean(numbers: Double...) -> Double {
var total: Double = 0
for number in numbers {
total += numbers
}
return total / Double(numbers.count)
}
arithmeticMean(1, 2, 3, 4, 5)
arithmeticMean(3, 8, 19)
求大神指点,找不到原因
找到原因了。。numbers多打了个s 展开
var total: Double = 0
for number in numbers {
total += numbers
}
return total / Double(numbers.count)
}
arithmeticMean(1, 2, 3, 4, 5)
arithmeticMean(3, 8, 19)
求大神指点,找不到原因
找到原因了。。numbers多打了个s 展开
- 你的回答被采纳后将获得:
- 系统奖励15(财富值+成长值)+难题奖励30(财富值+成长值)
2015-07-18
展开全部
func arithmeticMean(numbers: Double...) -> Double {
var total: Double = 0
for number in numbers {
total += number
}
return total / Double(numbers.count)
}
arithmeticMean(1, 2, 3, 4, 5)
// returns 3.0, which is the arithmetic mean of these five numbers
arithmeticMean(3, 8, 19)
// returns 10.0, which is the arithmetic mean of these three numbers
var total: Double = 0
for number in numbers {
total += number
}
return total / Double(numbers.count)
}
arithmeticMean(1, 2, 3, 4, 5)
// returns 3.0, which is the arithmetic mean of these five numbers
arithmeticMean(3, 8, 19)
// returns 10.0, which is the arithmetic mean of these three numbers
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
类型不对,重新定义类型
追问
是在for循环内 number多打了个s,我看了半天才发现这个问题
追答
func arithmeticMean(numbers: Double...) -> Double {
var total: Double = 0
for number in numbers {
total += number
}
return total / Double(numbers.count)
}
arithmeticMean(1, 2, 3, 4, 5)
// returns 3.0, which is the arithmetic mean of these five numbers
arithmeticMean(3, 8, 19)
// returns 10.0, which is the arithmetic mean of these three numbers
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询