Program in C ++ stops working

0

We were asked to develop a program that teaches English. It is ready, but the problem is that after a certain time of running the program, it stops working and says that the program must be closed. Why is that happening?

#include <iostream>
#include <allegro.h>

using namespace std;
int Menu();
int Practica1();
int Practica2();
int Practica3();
int Practica4();
int Practica5();
int Practica6();
int Practica7();
int Pregunta2();
int Pregunta3();
int Pregunta4();
int Pregunta5();
int Pregunta6();
int Pregunta7();
int Pregunta8();
int Pregunta9();
int Pregunta10();
int Contador();
int contador=0, c1=0, c2=0, c3=0, c4=0, c5=0, c6=0, c7=0, c8=0, c9=0, c10=0;
bool finalizar=true;
bool continuar=true;
bool opcion=true;

BITMAP *fondo;
BITMAP *practice;
BITMAP *quizz;
BITMAP *practice1;
BITMAP *quizz1;
BITMAP *p2;
BITMAP *p3;
BITMAP *p4;
BITMAP *p5;
BITMAP *p6;
BITMAP *p7;
BITMAP *q1;
BITMAP *q2;
BITMAP *q3;
BITMAP *q4;
BITMAP *q5;
BITMAP *q6;
BITMAP *q7;
BITMAP *q8;
BITMAP *q9;
BITMAP *q10;
BITMAP *incorrecto;
BITMAP *correcto;
BITMAP *sigue;
BITMAP *excelente;
int main()
{
  allegro_init();
  set_color_depth(16);
  set_gfx_mode(GFX_AUTODETECT_WINDOWED, 800,600,0, 0);

  install_keyboard();
  install_mouse();
  show_mouse(screen);

  Menu();

  allegro_exit();
  return 0;
}

int Menu()
{
  continuar=true;

  BITMAP *exit;

  fondo = load_bitmap("fondo.bmp", NULL);

  draw_sprite(screen, fondo, 0,0);


  while(!key[KEY_ESC] && continuar)
  {

    if (mouse_x > 300 && mouse_x < 481 && mouse_y > 216 && mouse_y < 263)
    {
        practice = load_bitmap("practice.bmp",NULL);
        draw_sprite(screen, practice, 0,0);

        if (mouse_x > 297 && mouse_x < 474 && mouse_y > 213 && mouse_y < 269)
        {
          if (mouse_b&1)
          {
            Practica1();
          }
         }
    }

    else if (mouse_x  > 300  && mouse_x < 481 && mouse_y > 289  && mouse_y < 342)
    {

      quizz = load_bitmap("quizz.bmp",NULL);
      draw_sprite(screen, quizz,0,0);

      if(mouse_b&1)
      {
        while(!key[KEY_ESC])
        {
          q1 = load_bitmap("q1.bmp", NULL);
          draw_sprite(screen, q1, 0,0);

          if (mouse_b&1)
          {
            if(mouse_x > 94 && mouse_x < 121 && mouse_y >322 && mouse_y < 348 )
            {
              while(!key[KEY_ESC])
              {
                incorrecto= load_bitmap("incorrecto.bmp", NULL);
                draw_sprite(screen, incorrecto, 0,0);

                if(key[KEY_ENTER])
                {

                  if(!key[KEY_ESC])
                  {

                    return Pregunta2();

                  }

                }
              }
            }

            else if(mouse_x > 95 && mouse_x < 122 && mouse_y > 391 && mouse_y < 418)
            {
              while(!key[KEY_ESC])
              {
                incorrecto= load_bitmap("incorrecto.bmp", NULL);
                draw_sprite(screen, incorrecto, 0,0);

                if(key[KEY_ENTER])
                {

                  if(!key[KEY_ESC])

                  {
                    return Pregunta2();


                  }

                }
              }

            }

            else if (mouse_x > 97 && mouse_x < 124 && mouse_y > 471 && mouse_y < 497)
            {
              while(!key[KEY_ESC])
              {



                correcto= load_bitmap("correcto.bmp", NULL);
                draw_sprite(screen, correcto, 0,0);

                c1=1;



                if(key[KEY_ENTER])
                {

                  if(!key[KEY_ESC])
                  {
                    return Pregunta2();

                   }
                }
              }
             }
          }
        }
      }
    }
    else if (mouse_x > 300 && mouse_x < 481 && mouse_y > 372 && mouse_y < 432)
    {

      exit = load_bitmap("exit.bmp",NULL);
      draw_sprite(screen, exit,0,0);

      if(mouse_b&1)
      {
        destroy_bitmap(fondo);
        destroy_bitmap(practice1);
        destroy_bitmap(practice);
        destroy_bitmap(quizz1);
        destroy_bitmap(p2);
        destroy_bitmap(p3);
        destroy_bitmap(p4);
        destroy_bitmap(p5);
        destroy_bitmap(p6);
        destroy_bitmap(p7);
        destroy_bitmap(q1);
        destroy_bitmap(q2);
        destroy_bitmap(q3);
        destroy_bitmap(q4);
        destroy_bitmap(q5);
        destroy_bitmap(q6);
        destroy_bitmap(q7);
        destroy_bitmap(q8);
        destroy_bitmap(q9);
        destroy_bitmap(q10);
        destroy_bitmap(incorrecto);
        destroy_bitmap(correcto);
        destroy_bitmap(sigue);
        destroy_bitmap(excelente);

        continuar = false;

        return 0;
      }
    }

    else
    {
      draw_sprite(screen, fondo, 0,0);
    }

  }
  return  1;

}

int Practica1()
{
  finalizar=true;

  while(!key[KEY_ESC])
  {
    practice1=load_bitmap("p1.bmp", NULL);
    draw_sprite(screen, practice1, 0,0);

    if(mouse_x > 11 && mouse_x < 43 && mouse_y > 61 && mouse_y < 101)
    {
      if (mouse_b&1)
      {
         return Menu();
      }
    }

    else if(key[KEY_ENTER])
    {
      rest (100);
       return Practica2();
    }

    else
    {
      draw_sprite(screen,practice1,0,0);
    }

  }

  return 1;

}
int Practica2()
{
  while (!key[KEY_ESC])
  {
    p2 =load_bitmap("p2.bmp",NULL);
    draw_sprite(screen,p2,0,0);

    if (mouse_x > 11 && mouse_x < 43 && mouse_y > 61 && mouse_y < 101)
    {
      if (mouse_b&1)
      {
        rest(1000);
         return Practica1();
      }
    }

    else if(key[KEY_ENTER])
    {
      rest (100);
       return Practica3();

    }

    else
    {
      draw_sprite(screen,p2,0,0);
    }
  }

  return 1;
}

int  Practica3()
{
  while (!key[KEY_ESC])
  {
    p3 =load_bitmap("p3.bmp",NULL);
    draw_sprite(screen,p3,0,0);

    if (mouse_x > 11 && mouse_x < 43 && mouse_y > 61 && mouse_y < 101)
    {
      if (mouse_b&1)
      {
        rest(1000);
         return Practica2();
      }
    }

    else if(key[KEY_ENTER])
    {
      rest (100);
       return Practica4();

    }

    else
    {
      draw_sprite(screen,p3,0,0);
    }
  }

  return 1;
}
int Practica4()
{
  while (!key[KEY_ESC])
  {
    p4 =load_bitmap("p4.bmp",NULL);
    draw_sprite(screen,p4,0,0);

    if (mouse_x > 11 && mouse_x < 43 && mouse_y > 61 && mouse_y < 101)
    {
      if (mouse_b&1)
      {
        rest(1000);
        return  Practica3();
      }
    }

    else if(key[KEY_ENTER])
    {
      rest (100);
      return Practica5();

    }

    else
    {
      draw_sprite(screen,p4,0,0);
    }
  }

  return 1;
}
int Practica5()
{
while (!key[KEY_ESC])
  {
    p5 =load_bitmap("p5.bmp",NULL);
    draw_sprite(screen,p5,0,0);

    if (mouse_x > 11 && mouse_x < 43 && mouse_y > 61 && mouse_y < 101)
    {
      if (mouse_b&1)
      {
        rest(1000);
         return Practica4();
      }
    }

    else if(key[KEY_ENTER])
    {
      rest (100);
       return Practica6();

    }

    else
    {
      draw_sprite(screen,p5,0,0);
    }
  }

  return 1;
}
int Practica6()
{

  bool cont=true;
  while (!key[KEY_ESC])
  {
    p6 =load_bitmap("p6.bmp",NULL);
    draw_sprite(screen,p6,0,0);

    if (mouse_x > 11 && mouse_x < 43 && mouse_y > 61 && mouse_y < 101)
    {
      if (mouse_b&1)
      {
        rest(1000);
         return Practica5();
      }
    }

    else if(key[KEY_ENTER])
    {
      rest (100);
      return Practica7();

    }

    else
    {
      draw_sprite(screen,p6,0,0);
    }
  }

  return 0;
}
int Practica7()
{
  bool cont=true;

  while(!key[KEY_ESC] && cont)
  {
    p7=load_bitmap("p7.bmp", NULL);
    draw_sprite(screen, p7, 0,0);

     if (mouse_x > 11 && mouse_x < 43 && mouse_y > 61 && mouse_y < 101)
    {
      if (mouse_b&1)
      {
        rest(1000);
         return Practica6();
      }
    }
      else if(mouse_x > 702 && mouse_x < 778 && mouse_y > 300 && mouse_y < 403 )
    {
      if(mouse_b&1)
      {
        if(Menu()== 0)
        {
          cont=false;
          return 0;
        }
      }
    }

  }


  return 1;
}

int Pregunta2()
{
  while(!key[KEY_ESC])
  {
    q2 = load_bitmap("q2.bmp", NULL);
    draw_sprite(screen, q2, 0,0);

    if (mouse_b&1)
    {
      if(mouse_x > 94 && mouse_x < 121 && mouse_y >322 && mouse_y < 348 )
      {
        while(!key[KEY_ESC])
        {
          incorrecto= load_bitmap("incorrecto.bmp", NULL);
          draw_sprite(screen, incorrecto, 0,0);

          if(key[KEY_ENTER])
          {

            while(!key[KEY_ESC])
            {
              return Pregunta3();


            }

          }
        }
      }

      else if(mouse_x > 95 && mouse_x < 122 && mouse_y > 391 && mouse_y < 418)
      {
        while(!key[KEY_ESC])
        {
          correcto= load_bitmap("correcto.bmp", NULL);
          draw_sprite(screen, correcto, 0,0);

          c2=1;

          if(key[KEY_ENTER])
          {

            if(!key[KEY_ESC])
            {
              return  Pregunta3();
            }
          }
        }
      }

      else if (mouse_x > 97 && mouse_x < 124 && mouse_y > 471 && mouse_y < 497)
      {
        while(!key[KEY_ESC])
        {
          incorrecto= load_bitmap("incorrecto.bmp", NULL);
          draw_sprite(screen, incorrecto, 0,0);

          if(key[KEY_ENTER])
          {
             if(!key[KEY_ESC])
            {
              return Pregunta3();

            }

          }
        }
      }

    }
  }

  return 1;
}
int Pregunta3()
{

  while(!key[KEY_ESC])
  {
    q3 = load_bitmap("q3.bmp", NULL);
    draw_sprite(screen, q3, 0,0);

    if (mouse_b&1)
    {
      if(mouse_x > 94 && mouse_x < 121 && mouse_y >322 && mouse_y < 348 )
      {
        while(!key[KEY_ESC])
        {
          correcto= load_bitmap("correcto.bmp", NULL);
          draw_sprite(screen, correcto, 0,0);

          c3=1;


          if(key[KEY_ENTER])
          {

            if(!key[KEY_ESC])
            {
              return  Pregunta4();

            }
          }
        }
      }

      else if(mouse_x > 95 && mouse_x < 122 && mouse_y > 391 && mouse_y < 418)
      {
        while(!key[KEY_ESC])
        {
          incorrecto= load_bitmap("incorrecto.bmp", NULL);
          draw_sprite(screen, incorrecto, 0,0);

          if(key[KEY_ENTER])
          {

            if(!key[KEY_ESC])
            {
              return  Pregunta4();

            }
          }
        }
      }

      else if (mouse_x > 97 && mouse_x < 124 && mouse_y > 471 && mouse_y < 497)
      {
        while(!key[KEY_ESC])
        {
          incorrecto= load_bitmap("incorrecto.bmp", NULL);
          draw_sprite(screen, incorrecto, 0,0);

          if(key[KEY_ENTER])
          {

            if(!key[KEY_ESC])
            {
              return  Pregunta4();

            }

          }
        }
      }

    }
  }

  return 1;
}
int Pregunta4()
{

  while(!key[KEY_ESC])
  {
    q4 = load_bitmap("q4.bmp", NULL);
    draw_sprite(screen, q4, 0,0);

    if (mouse_b&1)
    {
      if(mouse_x > 94 && mouse_x < 121 && mouse_y >322 && mouse_y < 348 )
      {
        while(!key[KEY_ESC])
        {
          incorrecto= load_bitmap("incorrecto.bmp", NULL);
          draw_sprite(screen, incorrecto, 0,0);

          if(key[KEY_ENTER])
          {

            if(!key[KEY_ESC])
            {
              return Pregunta5();

            }

          }
        }
      }

      else if(mouse_x > 95 && mouse_x < 122 && mouse_y > 391 && mouse_y < 418)
      {
        while(!key[KEY_ESC])
        {
          incorrecto= load_bitmap("incorrecto.bmp", NULL);
          draw_sprite(screen, incorrecto, 0,0);

          if(key[KEY_ENTER])
          {

            if(!key[KEY_ESC])
            {
              return Pregunta5();

            }

          }
        }
      }

      else if (mouse_x > 97 && mouse_x < 124 && mouse_y > 471 && mouse_y < 497)
      {
        while(!key[KEY_ESC])
        {



          correcto= load_bitmap("correcto.bmp", NULL);
          draw_sprite(screen, correcto, 0,0);

          c4=1;




          if(key[KEY_ENTER])
          {

            if(!key[KEY_ESC])
            {
              return  Pregunta5();

            }

          }
        }
      }

    }
  }

  return 1;
}
int Pregunta5()
{

  while(!key[KEY_ESC])
  {
    q5 = load_bitmap("q5.bmp", NULL);
    draw_sprite(screen, q5, 0,0);

    if (mouse_b&1)
    {
      if(mouse_x > 94 && mouse_x < 121 && mouse_y >322 && mouse_y < 348 )
      {
        while(!key[KEY_ESC])
        {
          incorrecto= load_bitmap("incorrecto.bmp", NULL);
          draw_sprite(screen, incorrecto, 0,0);

          if(key[KEY_ENTER])
          {

            if(!key[KEY_ESC])
            {
              return  Pregunta6();


            }
          }
        }
      }

      else if(mouse_x > 95 && mouse_x < 122 && mouse_y > 391 && mouse_y < 418)
      {
        while(!key[KEY_ESC])
        {
          incorrecto= load_bitmap("incorrecto.bmp", NULL);
          draw_sprite(screen, incorrecto, 0,0);

          if(key[KEY_ENTER])
          {

            if(!key[KEY_ESC])
            {
              return Pregunta6();


            }
          }
        }
      }

      else if (mouse_x > 97 && mouse_x < 124 && mouse_y > 471 && mouse_y < 497)
      {
        while(!key[KEY_ESC])
        {


          correcto= load_bitmap("correcto.bmp", NULL);
          draw_sprite(screen, correcto, 0,0);

          c5=1;



          if(key[KEY_ENTER])
          {

            if(!key[KEY_ESC])
            {
              return Pregunta6();


            }

          }
        }
      }

    }
  }
  return 1;
}
int Pregunta6()
{


  while(!key[KEY_ESC])
  {
    q6 = load_bitmap("q6.bmp", NULL);
    draw_sprite(screen, q6, 0,0);

    if (mouse_b&1)
    {
      if(mouse_x > 94 && mouse_x < 121 && mouse_y >322 && mouse_y < 348 )
      {
        while(!key[KEY_ESC])
        {
          incorrecto= load_bitmap("incorrecto.bmp", NULL);
          draw_sprite(screen, incorrecto, 0,0);

          if(key[KEY_ENTER])
          {

            if(!key[KEY_ESC])
            {
              return Pregunta7();

            }

          }
        }
      }

      else if(mouse_x > 95 && mouse_x < 122 && mouse_y > 391 && mouse_y < 418)
      {
        while(!key[KEY_ESC])
        {
          correcto= load_bitmap("correcto.bmp", NULL);
          draw_sprite(screen, correcto, 0,0);

          c6=1;

          if(key[KEY_ENTER])
          {

            if(!key[KEY_ESC])
            {
              return Pregunta7();


            }

          }
        }
      }

      else if (mouse_x > 97 && mouse_x < 124 && mouse_y > 471 && mouse_y < 497)
      {
        while(!key[KEY_ESC])
        {



          incorrecto= load_bitmap("incorrecto.bmp", NULL);
          draw_sprite(screen, incorrecto, 0,0);

          if(key[KEY_ENTER])
          {

            if(!key[KEY_ESC])
            {
              return Pregunta7();
            }

          }
        }
      }

    }
  }

  return 1;
}
int Pregunta7()
{


  while(!key[KEY_ESC])
  {
    q7 = load_bitmap("q7.bmp", NULL);
    draw_sprite(screen, q7, 0,0);

    if (mouse_b&1)
    {
      if(mouse_x > 94 && mouse_x < 121 && mouse_y >322 && mouse_y < 348 )
      {
        while(!key[KEY_ESC])
        {
          incorrecto= load_bitmap("incorrecto.bmp", NULL);
          draw_sprite(screen, incorrecto, 0,0);

          if(key[KEY_ENTER])
          {

            if(!key[KEY_ESC])
            {
              return Pregunta8();
            }

          }
        }
      }

      else if(mouse_x > 95 && mouse_x < 122 && mouse_y > 391 && mouse_y < 418)
      {
        while(!key[KEY_ESC])
        {
          correcto= load_bitmap("correcto.bmp", NULL);
          draw_sprite(screen, correcto, 0,0);

          c7=1;

          if(key[KEY_ENTER])
          {

            if(!key[KEY_ESC])
            {
              return  Pregunta8();
            }

          }
        }
      }

      else if (mouse_x > 97 && mouse_x < 124 && mouse_y > 471 && mouse_y < 497)
      {
        while(!key[KEY_ESC])
        {
          incorrecto= load_bitmap("incorrecto.bmp", NULL);
          draw_sprite(screen, incorrecto, 0,0);

          if(key[KEY_ENTER])
          {

            if(!key[KEY_ESC])
            {
              return  Pregunta8();
            }

          }
        }
      }

    }
  }

  return 1;
}
int Pregunta8()
{

  while(!key[KEY_ESC])
  {
    q8 = load_bitmap("q8.bmp", NULL);
    draw_sprite(screen, q8, 0,0);

    if (mouse_b&1)
    {
      if(mouse_x > 94 && mouse_x < 121 && mouse_y >322 && mouse_y < 348 )
      {
        while(!key[KEY_ESC])
        {
          incorrecto= load_bitmap("incorrecto.bmp", NULL);
          draw_sprite(screen, incorrecto, 0,0);

          if(key[KEY_ENTER])
          {

            if(!key[KEY_ESC])
            {
              return Pregunta9();
            }

          }
        }
      }

      else if(mouse_x > 95 && mouse_x < 122 && mouse_y > 391 && mouse_y < 418)
      {
        while(!key[KEY_ESC])
        {
          correcto= load_bitmap("correcto.bmp", NULL);
          draw_sprite(screen, correcto, 0,0);

          c8=1;

          if(key[KEY_ENTER])
          {

            if(!key[KEY_ESC])
            {
              return Pregunta9();
            }

          }
        }
      }

      else if (mouse_x > 97 && mouse_x < 124 && mouse_y > 471 && mouse_y < 497)
      {
        while(!key[KEY_ESC])
        {



          incorrecto= load_bitmap("incorrecto.bmp", NULL);
          draw_sprite(screen, incorrecto, 0,0);




          if(key[KEY_ENTER])
          {

            if(!key[KEY_ESC])
            {
              return Pregunta9();


            }

          }
        }
      }

    }
  }

  return 1;
}
int Pregunta9()
{

  while(!key[KEY_ESC])
  {
    q9 = load_bitmap("q9.bmp", NULL);
    draw_sprite(screen, q9, 0,0);

    if (mouse_b&1)
    {
      if(mouse_x > 94 && mouse_x < 121 && mouse_y >322 && mouse_y < 348 )
      {
        while(!key[KEY_ESC])
        {
          correcto= load_bitmap("correcto.bmp", NULL);
          draw_sprite(screen, correcto, 0,0);

          c9=1;

          if(key[KEY_ENTER])
          {

            if(!key[KEY_ESC])
            {
              return  Pregunta10();

            }

          }
        }
      }

      else if(mouse_x > 95 && mouse_x < 122 && mouse_y > 391 && mouse_y < 418)
      {
        while(!key[KEY_ESC])
        {
          incorrecto= load_bitmap("incorrecto.bmp", NULL);
          draw_sprite(screen, incorrecto, 0,0);

          if(key[KEY_ENTER])
          {

            if(!key[KEY_ESC])
            {
              return  Pregunta10();


            }

          }
        }
      }

      else if (mouse_x > 97 && mouse_x < 124 && mouse_y > 471 && mouse_y < 497)
      {
        while(!key[KEY_ESC])
        {


          incorrecto= load_bitmap("incorrecto.bmp", NULL);
          draw_sprite(screen, incorrecto, 0,0);



          if(key[KEY_ENTER])
          {

            if(!key[KEY_ESC])
            {
              return Pregunta10();


            }

          }
        }
      }

    }
  }

  return 1;

}
int Pregunta10()
{

  while(!key[KEY_ESC])
  {
    q10 = load_bitmap("q10.bmp", NULL);
    draw_sprite(screen, q10, 0,0);

    if (mouse_b&1)
    {
      if(mouse_x > 94 && mouse_x < 121 && mouse_y >322 && mouse_y < 348 )
      {
        while(!key[KEY_ESC])
        {
          incorrecto= load_bitmap("incorrecto.bmp", NULL);
          draw_sprite(screen, incorrecto, 0,0);

          if(key[KEY_ENTER])
          {

            if(!key[KEY_ESC])
            {
              return Contador();
            }

          }
        }
      }

      else if(mouse_x > 95 && mouse_x < 122 && mouse_y > 391 && mouse_y < 418)
      {
        while(!key[KEY_ESC])

        {
          correcto= load_bitmap("correcto.bmp", NULL);
          draw_sprite(screen, correcto, 0,0);

          c10=1;

          if(key[KEY_ENTER])
          {

            if(!key[KEY_ESC])
            {
              return Contador();


            }

          }
        }
      }

      else if (mouse_x > 97 && mouse_x < 124 && mouse_y > 471 && mouse_y < 497)
      {
        while(!key[KEY_ESC])
        {

          incorrecto= load_bitmap("incorrecto.bmp", NULL);
          draw_sprite(screen, incorrecto, 0,0);

          if(key[KEY_ENTER])
          {

            if(!key[KEY_ESC])
            {
              return Contador();


            }

          }
        }
      }

    }
  }

  return 1;
}
int Contador()
{
  bool opcion=true;

  contador=c1+c2+c3+c4+c5+c6+c7+c8+c9+c10;

  while(!key[KEY_ESC] && opcion)
  {
    if( contador < 7)
    {

      sigue=load_bitmap("sigue.bmp", NULL);
      draw_sprite(screen, sigue, 0,0);
      if(mouse_x > 717 && mouse_x < 776 && mouse_y > 481 && mouse_y < 570 )
      {

        if(mouse_b&1)
        {

          if(Menu()==0)
          {
            opcion=false;
            return 0;
          }

        }
      }

    }
    else
    {

      excelente=load_bitmap("excelente.bmp", NULL);
      draw_sprite(screen, excelente, 0,0);


      if(mouse_x > 690 && mouse_x < 764 && mouse_y > 469 && mouse_y < 570 )
      {

        if(mouse_b&1)
        {

          if(Menu()==0)
          {
            opcion=false;
            return 0;
          }
        }
      }
    }
  }

  return 1;
}
END_OF_MAIN();
    
asked by Seitan 21.12.2016 в 01:28
source

1 answer

3

Without looking too closely I see that the pointers are not initialized:

BITMAP *p4;

Then later you will not know if you should release the associated memory or not ... So this:

destroy_bitmap(p4);

It is liable to cause an error if the bitmap has not been created in the end because it will try to free memory that you have not reserved.

    
answered by 21.12.2016 в 08:00