I want to do a program that you can enter an integer than it will sum all of its digits.
example: 189
1+8+9=18
but I have an error.My program does this;
example: 189
189+89+90=368
what should I do? Here is my code
<code>
int counter=0,sum=0;
char n[100];
cin>>n;
while(n[counter]!=NULL){
counter++;
}
for(int i=0;i<=counter;i++){
sum=atoi(&n[i])+sum;
cout<<(&n[i])<<endl;
}
cout<<sum<<endl;
</code>