I cannot find why it isn't working. It outputs the number I inputted but with 1 digit less. Ex: 12345 ---> 1234.
I have already tried changing the while loop for a for one adding ifs and removing the parentheses.
#include <iostream>
using namespace std;
int num0, num1, x, y, z, num2;
int main()
{
cout << "input your number \n";
cin >> num0;
y = 0;
x = 1;
z = -1;
num2 = 0;
while (num0 > y)
{
y = (y * 10) + 9;
z++;
}
while (z >= 0)
{
num1 = num0 / (10 ^ z);
num0 = num0 - (num1 * 10 ^ z);
z--;
num2 += num1;
}
cout << num2;
}
I want to input any number and then add the individual digits. Ex: 56868947 = 5+6+8+6+8+9+4+7 = 53