# need some help

• 03-20-2002
_Will333_
need some help
Ok, what I'm trying to do is take an integer and display each digit, one per line, in reverse order:

// num = 123
//displays
3
2
1

and in normal order
// num = 123
1
2
3

I've figured out how to do the first one with % and / but am unsure how to do this to the next one...? I have a feeling its just a minor change but its beyond me right now. :confused:

The code I'm using for the first function is:

Code:

```void rightToLeft(int num) {         if (num < 10)         {                 cout << num << endl;         }         else         {                 cout << (num % 10) << endl;                 rightToLeft(num/10);         } }```
Any help would be greatly appreciated :)
• 03-20-2002
ihsir
cin>>num;
do
{
rem=num%10;
num=num/10;
cout<<rem<<"\n";
}
while(num>0);

maybe something like this...
• 03-20-2002
_Will333_
Quote:

Originally posted by ihsir
cin>>num;
do
{
rem=num%10;
num=num/10;
cout<<rem<<"\n";
}
while(num>0);

maybe something like this...

The one I'm having trouble with it outputting it in normal order, I already figured out how to do it in reverse order. Thanks, though. :) (sorry if I'm not makin much sense...its a bit late...probably the reason why this is giving me so much trouble, too!)
• 03-20-2002
_Will333_
nevermind, got it:

Code:

```        int count = 1;         double temp = num;         while (temp > 10)         {                 temp = temp / 10;                 count++;         }         while (count > 0)         {                 num = temp;                 cout << num % 10 << endl;                 temp = temp * 10;                 count--;         }```
just need to manipulate that into a recursive function (since thats what the problem is on)
• 03-20-2002