My brain has just hit a wall and I'm not sure how to do this without going into an infinite loop and I mean both my brain and the code! No idea if I have over complicated it to the max or if I am on the right track. Any help would be much appreciated!
The problem:
I want to print a list of numbers similar to a Fizz Buzz sequence but instead they say "Hello", "Red", "Green" and "Blue" from 0 to 24. I want to use a for loop but I am stuck on how to add the logic for every occurrence.
For even numbers I want it to print "Hello" and I have already worked that out using modulo.
Now, I want Red, Green and Blue to start at different places but obey the same equation of: "x + 6" at their respective starting points 1, 3 and 5.
I'm not sure how I can assign the values within the array(s) to the "i" variable of the for loop
Objectives:
Be able to print "Hello" for every even number.
Be able to print "Red" at = {1, 7, 13, 19}.
Be able to print "Green" at = {3, 9, 15, 21}.
Be able to print "Blue" at = {5,11,17,23}.
My code in C:
int main ()
{
int i,j,k,m;
int R[] = {1,7,13,19};
int G[] = {3,9,15,21};
int B[] = {5,11,17,23};
for (i = 0; i < 24; i++)
{
/* Even Numbers */
if (i % 2)
{
printf("Hello\n", i);
}
/* Odd Numbers */
if (i % 2 == 1)
{
for (j = 0; j < 4; j++)
{
/* Red */
if (i = R[j])
printf("Red\n", i);
}
for (k = 0; k < 4; k++)
{
/* Green */
if (i = G[k])
printf("Green\n", i);
}
for (m = 0; m < 4; m++)
{
/* Blue */
if (i = B[m])
printf("Blue\n", i);
}
}
}
return 0;
}
Sample Output:
0 Hello
1 Red
2 Hello
3 Green
4 Hello
5 Blue
6 Hello