Hello, I am not struggling with OpenGL and have this particular problem:

I'd like to draw a cylinder myself. Not just use gluCylinder() and everything. It is interesting for me to know, how to do it.

I've started with octagon, drew two of them, put them on top of each other in some distance. Then I drew the cover to make it cylindrical.

!And then the cage came down!

It started to do weird things, it drew covering and one octagon and that was it. No cylinder what so ever! I spend a lot of time figuring out how to fix it, but I didn't succeed

Here is the code, I'd like to ask some kind people to find this particular mistake or so.
I've commented it here and there to make it easier.

Code:
#include "cstdio"
#include "GL/glut.h"
#include "math.h"

void drw_polygon(int n = 3, int arg = 0, float mult = 1, float v = 1.0) {
    /*
        Function drw_polygon:
        Arguments:
            n - number of sides
            arg - starting angle (not so important at all)
            mult - multiplying sides to incrase their length
            v - cylinder height
    */

    // DumbProof Double Check :)
    if (arg < 0)
        arg = 0;

    // Cylinder Bottom
    glBegin(GL_POLYGON);
        glColor4f(1.0, 0.0, 0.0, 1.0);
        for(int i = arg; i <= (360 + arg); i += (360 / n)) {
            float a = i * M_PI / 180; // degrees to radians
            glVertex3f(mult * cos(a), mult * sin(a), 0.0);
        }
	glEnd();

    // Cylinder Top
	glBegin(GL_POLYGON);
        glColor4f(0.0, 0.0, 1.0, 1.0);
        for(int i = arg; i <= (360 + arg); i += (360 / n)) {
            float a = i * M_PI / 180; // degrees to radians
            glVertex3f(mult * cos(a), mult * sin(a), v);
        }
	glEnd();

    // Cylinder "Cover"
	glBegin(GL_QUAD_STRIP);
        glColor4f(1.0, 1.0, 0.0, 1.0);
        for(int i = arg; i < 480; i += (360 / n)) {
            float a = i * M_PI / 180; // degrees to radians
            glVertex3f(mult * cos(a), mult * sin(a), 0.0);
            glVertex3f(mult * cos(a), mult * sin(a), v);
        }
	glEnd();



}

void display() {
	glClear(GL_COLOR_BUFFER_BIT);
    glRotatef(0.05, 1.0, 1.0, 0.0);
    drw_polygon(3, 0, 2, 4);
	glutSwapBuffers();
}

void timer(int = 0) {
	display();
	glutTimerFunc(1, timer, 0);
}

int main(int argc, char **argv) {
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
	glutInitWindowSize(500, 500);
	glutInitWindowPosition(200, 200);
	glutCreateWindow("Cylinder");
	glClearColor(0.0, 0.0, 0.0, 1.0);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(-5, 5, -5, 5, -5, 5);
	glutDisplayFunc(display);
	timer();
	glutMainLoop();
}
Thanks for any help!