The file.exe stops working

0

I'm doing a blackjack simulator but when compiling the .exe file it stops working, showing the empty console. I leave the main in case the problem is there.

int main(){  
Baraja *Inglesa;
Jugador *Jugador1;
Jugador *Jugador2;
Crupier *crupier;
int a=0;
int b=0;
int c=0;
Inglesa->barajar();
cout<<"Bienvenidos al Blackjack"<<endl;
for (int i = 0; i<2; i++){
    a = Inglesa->robar()->getNumero() + a;
    b = Inglesa->robar()->getNumero() + b;
    c = Inglesa->robar()->getNumero() + c;  
}
Jugador1->setPuntaje(a);
Jugador2->setPuntaje(b);
crupier->setPuntaje(c);

cout<<"Jugador 1 tu puntaje inicial es: "<<Jugador1->getPuntaje()<<endl;
Jugador1->Jugar(Inglesa);
cout<<"Jugador 2 tu puntaje inicial es: "<<Jugador2->getPuntaje()<<endl;
Jugador2->Jugar(Inglesa);
crupier->Jugar(Inglesa);

if(Jugador1->getPuntaje() > Jugador2->getPuntaje() && Jugador1->getPuntaje() > crupier->getPuntaje() )
{
    cout<<"El Jugador 1 es el ganador!";
}
if(Jugador2->getPuntaje() > Jugador1->getPuntaje() && Jugador2->getPuntaje() > crupier->getPuntaje() )
{
    cout<<"El Jugador 2 es el ganador!";
}
else{
    cout<<"Gana la mesa";
}

return 0;}
    
asked by Bishuu 09.10.2017 в 04:14
source

1 answer

2
int main() {
  Baraja *Inglesa; // 1

  // ...

  Inglesa->barajar(); // 2

  // ...

In 1 you are declaring a pointer and in 2 you use it as if nothing ... where does that pointer point to? Before using any type of variable, you must initialize it:

Baraja *Inglesa = new Baraja;

Although viewing your program does not make much sense to use pointers here. This would simplify enough since the constructor could be invoked implicitly:

Baraja inglesa; // El constructor se invoca implicitamente

And, of course, if you choose to continue using pointers do not forget to release the memory before leaving the program:

delete Inglesa;

Note: What I tell you about initializing the pointers is equally applicable to Jugador1 , Jugador2 and crupier

    
answered by 09.10.2017 в 07:37