int i = (rand()%2)+1; // generating random number
switch(i) // part where i suspect the problem to be
{
case 1:
for (int a = 0; a < 6 ; )
{
int g = 6;
int x = 0;
x++;
ColorPlace[a] = x; // where the first RED or blue is going to be
ColorPlace2[a] = g; // where the second RED or BLUE is going to be
g++;
cout << a << endl; // i made some testing that the loop is running...
a++; // ..and it was!
}
for (int a = 0;a < 6;) // some more testing
{
// the problem is that the numbers for where (ex: RED or Blue) should be..
// dont change they are always the same
cout << ColorPlace[a] << endl;
cout << ColorPlace2[a] << endl;
Sleep(1500);
a++;
}
break;
case 2: // this part of code is for now the same it will be changed
for (int a = 0; a < 6 ; )
{
int h = 6;
int y = 0;
y++;
ColorPlace[a] = y;
ColorPlace2[a] = h;
h++;
a++;
cout << a << endl;
}
for (int a = 0;a < 6;) // and yet again testing the code
{
cout << ColorPlace[a] << endl;
cout << ColorPlace2[a] << endl;
Sleep(1500);
a++;
}
break;
}
by testing different parts of the code I have pinpointed the problem to be
the for loop and switch statement
THE PROBLEM:
the problem is that the numbers for where (ex: RED or Blue) should be
dont change they are always the same
What am i doing wrong?
thank you!
for (int a = 0; a < 6 ; )
{
int g = 6;
int x = 0;
x++;
ColorPlace[a] = x; // where the first RED or blue is going to be
ColorPlace2[a] = g; // where the second RED or BLUE is going to be
g++;
cout << a << endl; // i made some testing that the loop is running...
a++; // ..and it was!
}
The problem is that your variables 'x' and 'g' are local variables of the for body. So for each iteration they are set correspondingly to 0 and 6. So there is no any sense in statements
x++;
g++;
You could change your code the following way
1 2 3 4 5 6 7 8 9 10
for (int a = 0, g = 6, x = 1; a < 6 ; a++, g++, x++ )
{
ColorPlace[a] = x; // where the first RED or blue is going to be
ColorPlace2[a] = g; // where the second RED or BLUE is going to be
cout << a << endl; // i made some testing that the loop is running...
// ..and it was!
}