Rubik's cube face generator...

Ok so I'm creating a program that will hopefully eventually be able to solve a Rubik's cube, but I'm having problems generating the actual cube.

I used numbers to test the function, but I'm getting weird output...

1
2
3
4
5
6
7
8
9
10
11
Ok, now, start at the top left of the up face,
and enter in the colors (red = r, green = g, etc)
in a right-to-left, top-to-bottom fashion:

1 2 3 // here i hit enter for clarity. the program works the same w/o the newline
4 5 6// here i hit enter for clarity. the program works the same w/o the newline
7 8 9
So you're saying the up face looks like this?
1 2 4
4 5 7
7 8 9 


Here's the code for this segment. Why are elements a[1][0] and a[2][0] showing up at a[0][2] and a[1][2]????

I tested this by checking what up[0][2] is in the main function, but even that is the incorrect number. Anyone know what's going on here?

BTW up[][] is defined globally like this: char up[2][2];

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
 50     do
 51     {
 52         createFace(up);
 53         cout << "So you're saying the up face looks like this?\n";
 54         printFace(up);
 55         cout << "\n>>> ";
 56         cin >> confirm;
 57         if (toupper(confirm) != 'Y')
 58             cout << "Ok, reenter the up face:\n\n";
 59     } while (toupper(confirm) != 'Y');
 60
 61     return 0;
 62 }
 63
 64 void createFace(char a[][2])
 65 {
 66     int i, j;
 67     for (i=0; i<=2; i++)
 68         for (j=0; j<=2; j++)
 69             cin >> a[i][j];
 70 }
 71
 72 void printFace(char a[][2])
 73 {
 74     int i, j;
 75     for (i=0; i<=2; i++)
 76     {
 77         for (j=0; j<=2; j++)
 78         {
 79             cout << a[i][j];
 80             cout << " ";
 81         }
 82         cout << "\n";
 83     }
 84 }
You're trying to stuff a 3x3 grid into a 2x2 array. How did you think that was going to work?

Valid indices for an array char array[size] are 0 to size-1. Note that if size is 2, 2 is not a valid index.
Wow thanks. It's been awhile since I worked with C++...
Topic archived. No new replies allowed.