The end of my program won't display.

I'm writing a program for class that plays the game 21 pick up where players take turns picking 1-3 stones and the player that takes the last one wins. My problem is that when it gets to where it should display the winner, the program closes. Any advice or help would be appreciated.

#include <cmath>
#include <iostream>

using namespace std;

int total = 21;
int move;
bool win1 = false;

void winner()
{
if (win1)
{
cout << "Player 1 wins!";
}

else
{
cout << "Player 2 wins!";
}
}

void printstones()
{
cout << "The number of stones remaining is " << total << endl;
}


int player2()
{
cout << "Player two, please enter your move: ";
cin >> move;
cin.ignore(1000,10);

while (move < 1 || move > 3)
{
cout << "That is not a valid move. Please enter either 1,2, or 3: ";
cin >> move;
cin.ignore(1000,10);
}

total -= move;

return total;
}


int player1()
{
cout << "Player one, please enter your move: ";
cin >> move;
cin.ignore(1000,10);

while (move < 1 || move > 3)
{
cout << "That is not a valid move. Please enter either 1,2, or 3: ";
cin >> move;
cin.ignore(1000,10);
}

total -= move;
if (total == 0)
{
win1 = true;
}
return total;
}

int main()
{

cout << "Let's play 21 pickup." << endl;
cout << "Players will take turns picking 1, 2, or 3 stones to remove from the pile." << endl;
cout << "The player who removes the last stone wins!" << endl;

while (total > 0)
{

total = player1();

while (total < 0)
{
cout << "That is an illegal move. Please try again." << endl;
total += move;
total = player1();
}
if (total == 0) break;
printstones();

total = player2();

while (total < 0)
{
cout << "That is an illiegal move. Please try again." << endl;
total += move;
total = player2();
}
if (total == 0) break;
printstones();
}
winner();
return 0;
}
see the sticky thread here:

http://cplusplus.com/forum/beginner/1988/
There are a number of different ways to keep the console from closing when the program ends. They are discussed in the following link ad nauseum:
http://www.cplusplus.com/forum/beginner/1988/
Topic archived. No new replies allowed.