#include <iostream>
usingnamespace std;
int inputnum,changenum;
int nr = 0;
int math = 1;
int parameter;
int main()
{
cout<<"Enter any number"<<endl;
cin>>inputnum;
changenum=inputnum;
for( int c=0; c<6;c++)
{
nr=nr+1;
inputnum=inputnum/10;
}
for (int i=1;i<nr;i++)
{
math=math*10;
}
while (changenum!=0)
{
parameter=changenum/math;
changenum=changenum%math;
math=math/10;
cout<<parameter<<endl;
}
return 0;
}
It works fine with a test input of 123456, but when you input 600000 it cuts off the zeros. Although it does work 600001.
I think it would be easier to simply use a std::stringstream/std::string combination to get the number into text format. Unless you have to use modulus/division, anyway.
Anyway...lines 18-22 don't seem to do anything other than make nr = 6 and divide input num by 10 6 times. Then the next loop just multiplies math by 10 5 times. Your variable names are kind of vague, I'm not really sure how "changenum" and "math" are supposed to be related until I read where they are used.
As for the problem, it's that after the first while loop, changenum % math will give you 0, so the loop will exit.
I think...if you mod the number by 10 and then output this remainder you have completed step #1
If you then divide the number by 10 and then mod the result by 10 and output tis remainder you will have completed the second step. Repeat 4 more times.