Searched your forums a lot, found a solution to my task, but still I do not understand why do I get the wrong answer everytime. It's always a 'correct-1' result. It doesn't depend on what the number in the string is.
#include <cstdlib>
#include <iostream>
#include <string.h>
using namespace std;
int main(int argc, char *argv[])
{
string s1;
int i, x, y;
char temp;
s1="1020401";
for(i=0;i<s1.length();i++) {
temp=s1[i];
x=x+atoi(&temp);
}
cout<<endl<<x<<endl;
system("PAUSE");
return EXIT_SUCCESS;
}
this gives me 7, but the correct result must be 8, what did I miss?
p.s. maybe something is written not good and some of you may show me my mistakes.