< previous page page_116 next page >

Page 116
LISTING 8.4 continued
d5ef64f4d3250b96ba5c07ca5bbc2f56.gif
4:    #include <iostream.h>
5:
6:    int main()
7:    {
8:       unsigned short small;
9:       unsigned long large;
10:      unsigned long skip;
11:      unsigned long target;
12:      const unsigned short MAXSMALL=65535;
13:
14:      cout < Enter a small number: ;
15:      cin >> small;
16:      cout < Enter a large number: ;
17:      cin >> large;
18:      cout < Enter a skip number: ;
19:      cin >> skip;
20:      cout < Enter a target number: ;
21:      cin >> target;
22:
23:      cout < \n;
24:
25:      // set up 3 stop conditions for the loop
26:      while (small < large && large > 0 && small < MAXSMALL)
27:
28:      {
29:
30:          small++;
31:
32:          if (small % skip == 0)  // skip the decrement?
33:          {
34:            cout < skipping on  < small < endl;
35:            continue;
36:          }
37:
38:          if (large == target)    // exact match for the target?
39:          {
40:            cout < Target reached!;
41:            break;
42:          }
43:
44:          large-=2;
45:      }                   // end of while loop
46:
47:      cout < \nSmall:  < small <  Large:  < large < endl;
48:      return 0;
48:   }

Output:
Enter a small number: 2
Enter a large number: 20

 
< previous page page_116 next page >

If you like this book, buy it!