Adding c-string

This assignment requires that I allow a user to enter a string of numbers without any spaces and add them up and find the high and low numbers in the string. Ex. 2514 = 12 highest digit 5, lowest 1 blah blah. The only way I can think to accomplish this is through the use of an array and and to step through each subscript using the atoi function to turn it into an interger and totaling it. The problem that I've run into is that instead of adding each member of the array individually. The input 123 returns the values 2460. Any hints would be much appreciated. Thank you in advance even though I know its a stupid question *sigh*.

cin.getline(addString, SIZE);

for (int count = 0; count < SIZE; count++)
{
addString[count];
total += atoi(addString);


}
You can convert the ASCII character '0' to the decimal value 0 by subtracting '0':

1
2
char ch = '5';
int num = ch - '0';  // num == 5. 


You can do it a couple of ways. You can read a string into an array, or you can
read one character at a time. If you think about it, you don't need an array at
all.
Topic archived. No new replies allowed.