I need some help with OpenGL C++ code for Rubik's cube. I created a Rubik's cube but I am having difficulty rotating each slice.

void colorcube()
{
for(i=0;i<=.66;i=i+.22)
{
for(j=0;j<=.66;j=j+.22)
{
for(k=0;k<=.66;k=k+.22)
{
glColor3fv(colors[1]);
glBegin(GL_POLYGON);
glVertex3f(i-.3,j-.3,k-.3);
glVertex3f(i-.3,j-.1,k-.3);
glVertex3f(i-.1,j-.1,k-.3);
glVertex3f(i-.1,j-.3,k-.3);
glEnd();
glColor3fv(colors[2]);
glBegin(GL_POLYGON);
glVertex3f(i-.3,j-.3,k-.3);
glVertex3f(i-.3,j-.1,k-.3);
glVertex3f(i-.3,j-.1,k-.1);
glVertex3f(i-.3,j-.3,k-.1);
glEnd();
glColor3fv(colors[3]);
glBegin(GL_POLYGON);
glVertex3f(i-.3,j-.3,k-.3);
glVertex3f(i-.3,j-.3,k-.1);
glVertex3f(i-.1,j-.3,k-.1);
glVertex3f(i-.1,j-.3,k-.3);
glEnd();
glColor3fv(colors[4]);
glBegin(GL_POLYGON);
glVertex3f(i-.1,j-.1,k-.3);
glVertex3f(i-.1,j-.3,k-.3);
glVertex3f(i-.1,j-.3,k-.1);
glVertex3f(i-.1,j-.1,k-.1);
glEnd();
glBegin(GL_POLYGON);
glColor3fv(colors[5]);
glVertex3f(i-.1,j-.1,k-.1);
glVertex3f(i-.3,j-.1,k-.1);
glVertex3f(i-.3,j-.3,k-.1);
glVertex3f(i-.1,j-.3,k-.1);
glEnd();
glBegin(GL_POLYGON);
glColor3fv(colors[6]);
glVertex3f(i-.1,j-.1,k-.1);
glVertex3f(i-.3,j-.1,k-.1);
glVertex3f(i-.3,j-.1,k-.3);
glVertex3f(i-.1,j-.1,k-.3);
glEnd();
}
}
}
}

Any help is greatly appreciated.

Coding style is not what i want to discuss.. i want to have rubiks cube where each slice should be able to rotate.. i want to do this opengl c++, not in c sharp.....