Hi,
I'm trying to make this program, where you enter 2-4 players and deal them number of cards by random generator, and print the final output out for each player. In the loop I have to use the bool function to check if the card has been dealt or not. My problem is I have a never ending loop, and yes conditions are there and it should quit, but somehow it doesn't. Any help would great. Thanks
Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
int main (void)
{
int playersNumb, cardsNumb;
int i, j, n, p, temp;
int card [52];
bool cardDealt = false;
printf("Please Enter Number of players: ");
scanf("%d",&playersNumb);
printf("Please Enter Number of cards being deal: ");
scanf("%d",&cardsNumb);
n=0;
j=0;
while (j < (playersNumb*cardsNumb)) //checking total numbers of cards dealt
{
for (i=0;i<playersNumb;i++)
{
while (n < cardsNumb) //checking cards dealt for each person
{
temp = rand();
for (p=0;p<n;p++)
{
if (card[p] == temp)
{
cardDealt = true; //checks if the card already exist
}
}
if (temp < 53 && cardDealt == false) //if random number less than 53 and card is still in the deck, stores it
{
card[j] = temp;
n++;
j++;
}
cardDealt = false;
}
}
}
i=1;
printf("Player %d - ",i);
for (j=1;j<=(playersNumb*cardsNumb);j++)
{
if (j%cardsNumb == 0) { //checks the modulus if 0 then breaks the line for next player
printf("\n");
printf("Player %d - ",i);
} else {
printf("%d ",card[j]);
}
i++;
}
system ("pause");
return 0;
}