Either my loop is bad or my function is messed up

This is a discussion on Either my loop is bad or my function is messed up within the C Programming forums, part of the General Programming Boards category; In my program I call this function:
Code:
int turnAgain(int status)
// function: turnAgain
// pre: Player must have rolled ...

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?

it has the effect of making it go through the loop again (I have to comment out the remaining code in the file to make it do this at this point) but I'm wondering if the if/else at the bottom of the loop would be better.

This is the basic outline of what i want to happen when I finally finish this:

1. roll dice and accumulate points until:
a. you roll a combination that eliminates your points
b. you chose to quit and total your score for the round

2. if a or b happen, it switches to the other player after tallying the points (if there are any)
3. the other player does the same thing until a or b happen
4. this goes on until someone has enough points to win. (you have to decide to stop before this condition is checked)
5. Then it announces the winner and spews out the totals for each player

So would an if else at the bottom of that loop be the best way to do it, and if so, how should I code it to make it return to the top of the loop?

Why not make a flowchart first? That way, you can write down what happens and where, to get an overview of how the logic is supposed to be done.
Then you choose an appropriate loop depending on how your flowchart looks like and translate it to code.
It simply cannot get any easier.

I've moved the statement to other locations (same with the "do") and get similar results. here is the current structure of my main:

Code:

int main (void)
{
// variable declarations
// do // play at least one game I started with the do statement here
{
//give option to print the rules only at the beginning of the game
do I just moved the do statement here, not sure if this iscorrect
{
die1 = rollDie();
die2 = rollDie();
sum = (die1 + die2);
printf("Die 1 is a %d.\n", die1);
printf("Die 2 is a %d.\n", die2);
if (turnPoints(die1, die2) == doublesPoints)
{
do stuff
}
else if (turnPoints(die1, die2) == onesPoints)
{
do stuff
}
else if (turnPoints(die1, die2) == noPoints)
{
do stuff and dont satisfy the condition to loop again
}
else if (turnPoints(die1, die2) == singlesPoints)
{
do stuff
}while (status != 0 && turnAgain(status) == 'y')
}it doesnt like the while statement here either
//this is line 209
if (turnAgain(status) == 'n')//(answer == 'n')
{
do stuff
}
//a bunch of stuff i commented out for now
} while (answer != 'n')
return 0;
}// this is line 251

I know you guys are frustrated with me and I appreciate your help a lot. I do have a flow diagram for this but I still have a very hard time with this. any additional help would be very much appreciated.
crazychile

{
variable declarations
give option to print rules
do
{
{
roll dice
award points per roll combination until condition is met
}
print the totals so far
switch player and repeat loop
if either player reaches 100 points
{
announce the winner and print totals
}
ask to play another game
if yes then repeat do
}
}

The design has been refined a bit as I went along. My instructor has made us turn in design documents that are generic in nature but not actual flow charts per se.

You can see that the logic has flaws.
Above all else, replace your "...until condition is met" and "...and repeat loop" (etc) with real loops and conditions.
Like
BEGIN LOOP
Roll dice
Award points per roll combination
If points == something REPEAT LOOP
END LOOP
But it really should be written on paper so you can see if a certain condition is false or true, it repeats, and you can see that by tracing the pointer that is written to it.

And then it seems fishy that you would ask if the user wants to play again when a game is not finished (the question is outside the if).

You can see that the logic has flaws.
Above all else, replace your "...until condition is met" and "...and repeat loop" (etc) with real loops and conditions.
Like
BEGIN LOOP
Roll dice
Award points per roll combination
If points == something REPEAT LOOP
END LOOP
But it really should be written on paper so you can see if a certain condition is false or true, it repeats, and you can see that by tracing the pointer that is written to it.

And then it seems fishy that you would ask if the user wants to play again when a game is not finished (the question is outside the if).

Thank you Elysia. I'm going to scratch out another version now. I get messed up with how to start and close loops. What is the rule for DO? I want it to do the main from the rules onward but I also dont want it to repeat the rules every round. What are the rules for starting and closing a DO?