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];

```
['https://Stackoverflow.com/questions/30723972', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3681431/']
There is nothing like decimal digits in an `int`. There are (mostly 32 or 64) *binary* digits (bits) and the base of 2 is not commensurable with the base of 10. You’ll need to divide your numbers by 10 to get decimal digits.

```
unsigned int DigitSum(unsigned int input, unsigned int base = 10)
{
    unsigned int sum = 0;
    while(input >= base)
    {
        sum += input % base;
        input /= base;
    }
    sum += input;
    return sum;
}

```

I used `unsigned int`. The example cannot be directly used for negative numbers but the modification is not difficult.
```
You can do like this,

#include<iostream>
#include <string>
#include <sstream>
using namespace std;
int main()
{
  int a[5]={1,2,5,11,12};
  int length = sizeof(a)/sizeof(int);
  for(int i=0;i<length;i++)
  {
        if ( a[i] >9 )
        {
                stringstream ss;
                ss << a[i];
                string a1 = ss.str();
                const  char * s = a1.c_str();
                int sum=0;
                while (*s !='\0')
                {
                        cout<<*s<<endl;
                        sum  += (*s - '0');
                        s++;
                }
                cout<<"num:"<< sum <<"\n";
        }
  }
}

```