Hey Tommy,
I understood what you want.And its not a stupid question as others
said(assuming that what I undersood was what u want).You gonna use little
math to solve it.Look,lets rephrase the question again: the user enters a
number (without spaces) in a one command line and u wanna add the digits of
that number.In other words (cin>>b) where b was entered as 1234.
so here is the code u use to add them:
int add_digits(void){
int i=1,sum=0,digit=0,number_reduced,b;
cin>>b;
number_reduced=(b / i);
while (number_reduced !=0 ){
digit=number_reduced%10; // to put this digit in temp2
sum = sum + digit; //u could use the += too,I just always confuse += with =+
i*=10;
number_reduced=(b / i);// to keep the digit that we want in the last
place(notice that temp1 is INT)
}
cout <<sum;
getch();
}
This will basically solve the problem.if u have a question about the
code,let me know. but u can go to alt.comp.learn.c-c++ if u are beginner
where u can find answers to easy questions.
Have a good day
Bye
"Tommy Lang" <mu*****@yahoo.se> wrote in message
news:78**************************@posting.google.c om...
Lets say you have a read (using cin >> ) a couple of numbers that the
user have entered ie. 1234. And you want to add these numbers together
like this, 1+2+3+4=10 How do you do that?
Thanks,
Tommy