Hi again. I am stuck with an infinte loop:
What I would like this to do is this:
When an 'x' is chosen it checks to see which set 'x' belongs to ('r', 'u', or 'c'). Depending on which set 'x' belongs to, I want that set to incrememnt. I never want 'r' to be above 3, 'u' to be above 20, or 'c' to be above 36. I want to add 59 values into 'deck', with the restriction that the value that is added cannot belong to a certain set more than the max value needed for that set (i.e. max val of 'r' is 3, so no more than 3 values that fall into the 'r' range can be added to the array 'deck'). Ultimately I want to end the program with an array ('deck') of 60 values (3 which fall into the 'r' category, 20 that fall into the 'u' category, 36 that fall into the 'c' category, and the number '1'). I hope this is understandable to everyone. If not, let me know and I will try to enlighten you.
Tnx
-rewclaus
Code:
int arr[18]; //an array of 18 integers (Iadding integers later)
int deck[60]; //empty to start
int j = 0;
int r = 0;
int u = 0;
int c = 0;
int i = 0;
deck[0] = 1;
for (i = 1; i < 60; i++)
{
j = 0;
while (j == 0)
{
x = ((323 * rand()) / (RAND_MAX)) + 7; //choose 'x' to be a random number between 7 and 330
k = (2 * rand()) / (RAND_MAX); //choose a random number between 0 and 2
if (k == 1)
{ x = arr[((18 * rand())/(RAND_MAX))]; } //choose 'x' to be a random value of the array 'arr'
printf("x = %d\n", x);
if ( (x >= 7) && (x <= 114) )
{ r++; }
if ( (x >= 115) && (x <= 222) )
{ u++; }
if ( (x >= 223) && (x <= 330) )
{ c++; }
if ( r > 3 )
{ continue; }
if ( u > 20 )
{ continue; }
if ( c > 36 )
{ continue; }
j = 1;
}
deck[i] = x;
}
What I would like this to do is this:
When an 'x' is chosen it checks to see which set 'x' belongs to ('r', 'u', or 'c'). Depending on which set 'x' belongs to, I want that set to incrememnt. I never want 'r' to be above 3, 'u' to be above 20, or 'c' to be above 36. I want to add 59 values into 'deck', with the restriction that the value that is added cannot belong to a certain set more than the max value needed for that set (i.e. max val of 'r' is 3, so no more than 3 values that fall into the 'r' range can be added to the array 'deck'). Ultimately I want to end the program with an array ('deck') of 60 values (3 which fall into the 'r' category, 20 that fall into the 'u' category, 36 that fall into the 'c' category, and the number '1'). I hope this is understandable to everyone. If not, let me know and I will try to enlighten you.
Tnx
-rewclaus