Hello, im a bit new to c++ and learning in my own, but im stuck to a problem.
Im trying to do a practice converting string/c-string to int :
Sum of Digits in a String
Write a program that asks the user to enter a series of single digit numbers with nothing
separating them. Read the input as a C-string or a string object. The program
should display the sum of all the single-digit numbers in the string. For example, if the
user enters 2514, the program should display 12, which is the sum of 2, 5, 1, and 4.
so i make a simple program first like this :
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
const int size = 5;
char array[size];
int acc = 0;//for accumulator
int number[5];
for(int count = 0; count < size; count++)
{
cout<<"enter a number = ";
cin>>array[count];
number[count] = atoi(array[count]);
acc += 0;
}
cout<<endl<<"the total number = "<<acc;
return 0;
}
but theres problem in 'atoi' to convert the string, the compiler says = 'atoi' : cannot convert parameter 1 from 'char' to 'const char *'
anyone can help me?