When I set the return value to double type in func, I get an error in return.
If anyone knows the cause, please let me know.
varpcascore: Array <Double > = [3.2, 2.4, 3.5, 1.3]
funcarrayplus(pcascore:Double...) - > Find the total value of the Double {// argument
variable —Double = 0.0
for n in pcascore {
total+=n
}
// print (total)
pcaallscore.append(total)
return pcaallscore
// Cannot convert return expression of type '[Double]' to return type 'Double'
// The error appears.
}
I think pcaallscore is a double list, and it's because it's a double (single variable) that should be returned.
If you want to return an array, define the function.
funcarrayplus (pcascore: Double...) - > Array <Double > {
Shouldn't it be?
You don't need pcaalscore.append(total)
to just return the sum.
I think return total
is fine.
© 2024 OneMinuteCode. All rights reserved.