Why C++ Graphics Program Not Quitting

Hi I a absolutely a newb in c++, opengl, and sdl, my goal is to make animations, music videos and even one day games, I have started out with sdl and opegl to make a window and change the colours, origionally I had a program to make a window but I altered it to change the colours and it initially crashed, I fixed that in the nested loops in main but then I noticed clicking the x at the top left of the window doesn’t make the program quit anymore!

Please help me fix this I just feel my skills are absolutely awful, thanks!

#include <SDL2/SDL.h>
#include <SDL2/SDL_opengl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include <stdio.h>
#include <string>

// -lSDL2 -lGLU -lglut -lGL

//Screen dimension constants
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;

//Starts up SDL and creates window
bool init();

//Frees media and shuts down SDL
void close();

//The window we'll be rendering to
SDL_Window* gWindow = NULL;

//The open gl square
float glSquareblk();
float glSquarerd();
float glSquaregrn();
float glSquarebl();

//Opengl context
SDL_GLContext gContext;

bool init()
{
	//Initialization flag
	bool success = true;

	//Initialize SDL
	if( SDL_Init( SDL_INIT_VIDEO ) < 0 )
	{
		printf( "SDL could not initialize! SDL_Error: %s\n", SDL_GetError() );
		success = false;
	}
	else
	{
		//Create window
		gWindow = SDL_CreateWindow( "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_OPENGL |  SDL_WINDOW_SHOWN );
		if( gWindow == NULL )
		{
			printf( "Window could not be created! SDL_Error: %s\n", SDL_GetError() );
			success = false;
		}
		else
		{
		
		}
	}

	return success;
}

void close()
{
	//Destroy window
	SDL_DestroyWindow( gWindow );
	gWindow = NULL;

	//Quit SDL subsystems
	SDL_Quit();
}

float glSquareblk()
{
	glClearColor(0.0,0.0,0.0,1.0);
	glClear(GL_COLOR_BUFFER_BIT);
	glColor3f(1.0,1.0,1.0);
	glOrtho(-1.0,1.0,-1.0,1.0,-1.0,1.0);
	glBegin(GL_QUADS);
		glVertex2f(-0.5,-0.5);
		glVertex2f(-0.5,0.5);
		glVertex2f(0.5,0.5);
		glVertex2f(0.5,-0.5);
		glEnd();
		glFlush();
}


float glSquarerd()
{
	glClearColor(1.0,0.0,0.0,1.0);
	glClear(GL_COLOR_BUFFER_BIT);
	glColor3f(1.0,1.0,1.0);
	glOrtho(-1.0,1.0,-1.0,1.0,-1.0,1.0);
	glBegin(GL_QUADS);
		glVertex2f(-0.5,-0.5);
		glVertex2f(-0.5,0.5);
		glVertex2f(0.5,0.5);
		glVertex2f(0.5,-0.5);
		glEnd();
		glFlush();
}


float glSquaregrn()
{
	glClearColor(0.0,1.0,0.0,1.0);
	glClear(GL_COLOR_BUFFER_BIT);
	glColor3f(1.0,1.0,1.0);
	glOrtho(-1.0,1.0,-1.0,1.0,-1.0,1.0);
	glBegin(GL_QUADS);
		glVertex2f(-0.5,-0.5);
		glVertex2f(-0.5,0.5);
		glVertex2f(0.5,0.5);
		glVertex2f(0.5,-0.5);
		glEnd();
		glFlush();
}


float glSquarebl()
{
	glClearColor(0.0,0.0,1.0,1.0);
	glClear(GL_COLOR_BUFFER_BIT);
	glColor3f(1.0,1.0,1.0);
	glOrtho(-1.0,1.0,-1.0,1.0,-1.0,1.0);
	glBegin(GL_QUADS);
		glVertex2f(-0.5,-0.5);
		glVertex2f(-0.5,0.5);
		glVertex2f(0.5,0.5);
		glVertex2f(0.5,-0.5);
		glEnd();
		glFlush();
}

int main( int argc, char* args[] )
{
	//Start up SDL and create window
	if( !init() )
	{
		printf( "Failed to initialize!\n" );
	}
	else
	{		
			//Main loop flag
			bool quit = false;
			
			gContext = SDL_GL_CreateContext( gWindow );
			
			//Event handler
			SDL_Event e;

			//While application is running
			while( !quit )
			{
				//Handle events on queue
				while( SDL_PollEvent( &e ) != 0 )
				{
					glSquareblk();
					SDL_Delay(3000);
					SDL_GL_SwapWindow( gWindow );
					
					glSquarerd();
					SDL_Delay(3000);
					SDL_GL_SwapWindow( gWindow );
					
					glSquaregrn();
					SDL_Delay(3000);
					SDL_GL_SwapWindow( gWindow );
					
					glSquarebl();
					SDL_Delay(3000);
					SDL_GL_SwapWindow( gWindow );
					
					//User requests quit
					if( e.type == SDL_QUIT )
					{
						quit = true;
					

	//Free resources and close SDL
	close();

	return 0;
}
}
}
}
}

Your code in this thread is identical to your previous post, where you had a problem with the window not closing whenever the X button in the upper right corner is pressed.
The thread I’m refering to is this:

Have you tried icculus’ solution to the problem?