Repeating Sequence of 0, 1, 2

Hi, I'm currently doing remote learning due to COVID-19, so everything I get teaching-wise from my professor is done through videos, in many of which she skips the examples that I feel would be helpful to understand. This is one of them and I have no idea where to start. It's at the beginning of the chapter so it feel like it should be simple.

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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
  #include <iostream>
using namespace std;

void print_array(int a[], int size);

int main()
{
   const int SIZE = 18;
   int a[SIZE];
   
   for (int i = 0; i < SIZE; i++)
   {
      /***Missing Code Here****/
      /** I had tried something like
      a[i] = i;
      if(a[i] > 2)
      {
       a[i] = a[i] - 2;
       }
      */




      
      
   }
   
   print_array(a, SIZE);

   return 0;
}

/**
   Prints an array of comma separated int.
   @param a the array of strings
   @param size the size of the array
*/
void print_array(int a[], int size)
{
   cout << "[";
   if (size > 0)
   {
      cout << a[0];
      for (int i = 1; i < size; i++)
      {
         cout << ", " << a[i];
      }
   }
   cout << "]" << endl;
}


Can anyone give me the first idea on how to tackle this? I added the code that I tried before but it gave me the wrong output. Thanks in advance for any help. Just to clarify, this is NOT homework, just a textbook example from Cay Horstmann's Big C++ Late Objects 3rd edition.
for (int i = 0; i < SIZE; ++i) a[i] = i % 3;
Thanks! Always forget about the modulus operator.
Topic archived. No new replies allowed.