help

write a compile and run a c++ program to reverse the digits of a positive integer number .use a do-while statement and continuously strip off and display the numbers units digit
Not quite what's asked for, but you should be able to pull it out of here..
(Observe the order of the stripped digits.)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
#include <cstdlib>
#include <ctime>

const char* desc[] =
    { "sexy", "curvaceous", "monstrous", "huge", "misshapen", "odd", "engorged" } ;

const std::size_t desc_size = sizeof(desc) / sizeof(desc[0]) ;

void strip( unsigned& num )
{
    unsigned digit = num % 10 ;
    std::cout << num << " strips, exposing its " 
              << desc[rand()%desc_size] << " digit: " << digit << '\n' ;
    num /= 10 ;
}

int main()
{
    std::cout << "enter a number: " ;
    unsigned n ;
    std::cin >> n ;

    while ( n )
        strip(n) ;

    std::cout << "Behold, " << n << " in all its naked glory!\n" ;
}


[edit: Also, don't make duplicate posts. Posting something 3 times is more likely to get you ignored than it is to get you a response. Please read:
http://www.cplusplus.com/forum/general/98395/
Particularly the part about titling posts. "help" is not helpful.]
Last edited on
Topic archived. No new replies allowed.