1.5. How to Use Arrays and Vectors

Following are the first eight elements from six numerical sequences:

Fibonacci:  1, 1, 2, 3, 5, 8, 13, 21 
Lucas:      1, 3, 4, 7, 11, 18, 29, 47 
Pell:       1, 2, 5, 12, 29, 70, 169, 408 
Triangular: 1, 3, 6, 10, 15, 21, 28, 36 
Square:     1, 4, 9, 16, 25, 36, 49, 64 
Pentagonal: 1, 5, 12, 22, 35, 51, 70, 92 

Our program must display a pair of elements from a sequence and allow the user to guess the next element. If the user guesses right and wishes to continue, the program then displays a second pair of elements, then a third, and so on. How might we do that?

If succeeding element pairs are taken from the same sequence, the user, recognizing one pair, recognizes them all. That is not very interesting. So we’ll pick an element ...

Get Essential C++ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.