Hi all. I've been busting my head for last two days with this problem. It should be fairly simple but since I'm a begginer it's rather confusing. I need to make a program that asks user to enter a number (let's say 34678) and then to output sum of those individual numbers (in this case that should be 28). I came up with this code that I tought will work but...
Code:
#include <iostream.h>
#include <stdlib.h>
void main()
{
char *num1 = "", *nume;
double lnum = 0, numt;
int i = 0;
cout << "Enter number: ";
cin >> num1;
while (num1[i])
{
char *tt = num1[i];
lnum = strtod(tt, &nume);
numt = (numt + lnum);
i++;
}
cout << numt;
}
Please help. Cheers.