In my program I call this function:
Code:
int turnAgain(int status)
// function: turnAgain
// pre: Player must have rolled a non disqualifying point combination
// post: returns a valid (y or n) answer
{
char ans;
if (status == 1)
{
printf("TURNAGAIN Would you like to risk the points for this round and continue? (y or n)? ");
getchar();
ans = getchar();
} //while (tolower(ans) != 'y' && tolower(ans) != 'n');
return tolower(ans);
}
after it completes determining the points and status for the roll(this is in the main):
Code:
{
die1 = rollDie();
die2 = rollDie();
sum = (die1 + die2);
printf("Die 1 is a %d.\n", die1);
printf("Die 2 is a %d.\n", die2);
//award points (rolled a double but not double 1's)
if (turnPoints(die1, die2) == doublesPoints)
{
do stuff
status = 1;
}
//award points (rolled double 1's)
else if (turnPoints(die1, die2) == onesPoints)
{
do stuff
status = 1;
}
//award no points (one of the two dice = 1)
else if (turnPoints(die1, die2) == noPoints)
{
do suff
status = 0;
}
//award points (rolled singles)
else if (turnPoints(die1, die2) == singlesPoints)
{
do stuff
status = 1;
}
if (turnAgain(status) == 'y');
}//end loop
//total the points for the player and switch to other player
if (turnAgain(status) == 'n');
{
total = (tempTotal + total);
if (currentPlayer == 1)
{
p1Total = updatePlayerTotal(currentPlayer, tempTotal,
p1Total);
}
else
{
p2Total = updatePlayerTotal(currentPlayer, tempTotal,
p2Total);
}
currentPlayer = switchPlayer(currentPlayer);
}
The code currently executes the loop once. When the function turnAgain is called, it will ask if you want to continue, but if you enter 'y', it will just keep asking until you enter 'n'. Then the code for (turnAgain(status) == 'n') prints like it should. I need it to keep looping back up to roll the dice again, etc. until a status = 0 condition happens or until I tell it to stop. Do I need another set of {} somewhere, or is my function faulty? What have I done wrong here?
Thanks a bunch,
crazychile