Im working on this program and most of it works except it has a few little problems. I cant pinpoint what is causing them, and I am kind of new to C, although I do have extensive experience with other languages. Anyway im hoping someone here can help, for one the loop is ending when just one of the two variables equals zero but both of them should have to equal one. And the other thing is its not stoping at the first getchar() it just goes straight to player2. Heres the code it has
Code:
int Roll(int nMark)
{
int nDie1;
int nDie2;
int nRoll;
int nP1Total = 0;
int nP2Total = 0;
char cP1Cont;
char cP2Cont;
int nP1Continue;
int nP2Continue;
printf("What would you like to roll too?: ");
scanf("%d", &nMark);
printf("\n\nThe object of this game is for two players to take turns throwing the dice. \n Each player can continue to throw trying to get the total of the throws \n as close to %d as possible.\n ", nMark);
system("PAUSE");
while((1 != nP1Continue) && (1 != nP2Continue))
{
if (nP1Continue != 1)
{
printf("\n\nPlayer 1, get ready to roll the dice. ");
system("PAUSE");
nDie1 = (rand() % 6) + 1;
nDie2 = (rand() % 6) + 1;
printf("\n\tFirst Die: %d", nDie1);
printf("\n\tSecond Die: %d", nDie2);
nP1Total = nP1Total + nDie1 + nDie2;
printf("\nPlayer 1, you stand at %d. Do you wish to continue rolling?(y/n): ",nP1Total);
cP1Cont = getchar();
if (('n' == cP1Cont) || ('N' == cP1Cont))
{
nP1Continue = 1;
}
}
if (nP2Continue != 1)
{
printf("\nPlayer 2, get ready to roll the dice. ");
system("PAUSE");
nDie1 = (rand() % 6) + 1;
nDie2 = (rand() % 6) + 1;
printf("\n\tFirst Die: %d", nDie1);
printf("\n\tSecond Die: %d", nDie2);
nP2Total = nP2Total + nDie1 + nDie2;
printf("\nPlayer 2, you stand at %d. Do you wish to continue rolling?(y/n): ",nP2Total);
cP2Cont = getchar();
if (('n' == cP2Cont) || ('N' == cP2Cont))
{
nP2Continue = 1;
}
}
}
}
some of the code may seem redundant but thats because i have been trying to fix these problems various ways. I appreciate any help you can provide thanks.