1. ## ending problem

okay here is the problem. You see I am writing a dice rolling game. Kinda like craps. I got the dice rolling part all worked out. But the problem is, When the player wins or loses, it closes. Soa ny help would be great.

Code:
```#include <cstdlib>
#include <iostream>
#include <time.h>

int rollDice( void );       // function prototype

using namespace std;

int main(int argc, char *argv[])
{
enum Status { CONTINUE, WON, LOST };
int sum, myPoint;
Status gameStatus;

srand( time( NULL ) );
sum = rollDice();

switch ( sum ) {
case 7:
case 11:
gameStatus = WON;
break;
case 2:
case 3:
case 12:
gameStatus = LOST;
break;
default:
gameStatus = CONTINUE;
myPoint = sum;
cout << "point is "<< myPoint;
break;
}

while ( gameStatus == CONTINUE ) { //keep rolling
sum = rollDice();

if ( sum == myPoint )
gameStatus = WON;
else
if ( sum == 7 )
gameStatus = LOST;
}

if ( gameStatus == WON )
cout << "player wins";
else
cout << "player loses";

return 0;

}

int rollDice( void )
{
int die1, die2, workSum;

die1 = 1 + rand() %6;
die2 = 1 + rand() %6;
workSum = die1 + die2;
cout << "player rolled " << die1 << " + " << die2
<< " = \n" << workSum;

system("PAUSE");
return workSum;
return EXIT_SUCCESS;
}```

2. You have a "return 0;' after the win or lose message. What are you expecting to happen?

3. hmm i didnt even see that.. thanks for pointing that out...
okay, i just took out the return 0; but, the thing is. It is still doing it. I'm now a bit lost..

4. The way I see it coded, it looks like it's supposed to close when they win or lose. If you want it to ask for a new game or continue then you have to the gamestatus == WON if statement into the loop and change the condition of the loop.

5. what should i do? I'm semi new and dont have much experence with loops. any ideas or examples would help. thanks.

6. Code:
```int rollDice( void )
{
int die1, die2, workSum;

die1 = 1 + rand() %6;
die2 = 1 + rand() %6;
workSum = die1 + die2;
cout << "player rolled " << die1 << " + " << die2
<< " = \n" << workSum;

system("PAUSE");
return workSum;
return EXIT_SUCCESS;
}```
That code will never be executed. Get rid of it.

Wait, did you just change that return 0 to return EXIT_SUCCESS?

7. I think when I started DEV it was on there. since i dont remember typing it.

8. Here, I added a newgame loop for you. Study what I did so you can understand it.

Code:
```#include <cstdlib>
#include <iostream>
#include <time.h>

int rollDice( void );       // function prototype

using namespace std;

int main(int argc, char *argv[])
{
enum Status { CONTINUE, WON, LOST };
int sum, myPoint;
char newGame;
Status gameStatus;

srand( time( NULL ) );

do {
sum = rollDice();
switch ( sum ) {
case 7:
case 11:
gameStatus = WON;
break;
case 2:
case 3:
case 12:
gameStatus = LOST;
break;
default:
gameStatus = CONTINUE;
myPoint = sum;
cout << "point is " << myPoint << endl;
break;
}

while ( gameStatus == CONTINUE ) { //keep rolling
sum = rollDice();
if ( sum == myPoint )
gameStatus = WON;
else if ( sum == 7 )
gameStatus = LOST;
}

if ( gameStatus == WON )
cout << "Player wins!" << endl;
else if ( gameStatus == LOST )
cout << "Player loses..." << endl;

cout << "New Game? (y/n)" << endl;
cin >> newGame;
} while (newGame == 'y' || newGame == 'Y');

return 0;

}

int rollDice( void )
{
int die1, die2, workSum;

die1 = 1 + rand() %6;
die2 = 1 + rand() %6;
workSum = die1 + die2;
cout << "player rolled " << die1 << " + " << die2
<< " = " << workSum << endl;

system("PAUSE");
return workSum;
return 0;
}```

9. Code:
```    return workSum;
return 0;```
Two return statements! Again!

10. OMG... i cant belive i didnt figure that.. Thank you very much.. you have helped me understand this just a bit more. i hope you all have a good day for helping me

11. Code:
`while (newGame == 'y' || newGame == 'Y');`
In cases like this, tolower() is your friend:
Code:
`while(tolower(newGame) == 'y');`

12. Originally Posted by dwks
Code:
`while (newGame == 'y' || newGame == 'Y');`
In cases like this, tolower() is your friend:
Code:
`while(tolower(newGame) == 'y');`
tolower(), I'll have to remember that one. Thanks.

13. Originally Posted by SlyMaelstrom
tolower(), I'll have to remember that one. Thanks.
as will I