I have an int array called doubledNumbers
and if a number in this array is greater than 9, I want to add the digits together. (example, 16 would become 1+6=7, 12 would become 3, 14 would become 5, etc)
Lets say I had the following numbers in doubledNumbers
:
12 14 16 17
I want to change the doubledNumbers
to:
3 5 7 8
I'm unsure how to do this for an int array as I get the error
invalid types 'int[int]' for array subscript
This is the code I have (thrown in a for
loop):
if (doubledNumbers[i]>9) {
doubledNumbers[i]=doubledNumbers[i][0]+doubledNumbers[i][1];