5 is easy, for those, just use the same as 1 but instead of 100, use 70.
that leaves 2/3/4
there are 2 ways to do this, I guess.
1) you can generate numbers and if they fail criteria, re-roll the number or
2) make a fancy random generator function(s) that do it for you. This would involve keeping track of the last number you made (to see if it is increasing or decreasing or that it is within 50 of previous, etc.
Condition 2: (rand() % 50 + prev_col_value - 25) % 70 (Note that this may lead to negative numbers) For second column be aware of Condition 3
Condition 3:
First col: When (row_index % 3) != 0
rand() % (70 - (prev_row_value + 1)) + prev_row_value + 1
otherwise -> rand() % (70 - 3)
Second col: Maybe you get the idea? Note: Condition 2
Note that you need to test this specifically with the extreme values.
Thank you or taking the time to answer me. I would like to say that am very new to CS and haven't developed an intuition that many here have, so speak to me as you would a slow person. This is hard for me.
so this is what i got from what you said (it's hard for me to look at it and say "of course" because my brain haven't really digest it fully):
My questions is, do i need to create another function to meet condition 3 and 4? or do I just put it here? I am still playing with it but kind of busy with another classwork to give it undivided attention.
1 2 3 4 5 6 7 8 9 10 11 12
void fillArray(int* array, int scenario, int Ndays, constint PROD)
{
for (int i = 0; i < scenario; i++)
for (int j = 0; j < Ndays; j++)
for(int k = 0; k < PROD; k++)
{
int randNumA = (rand() % MAX);
int randNumB = abs((rand() % 50+ *(array) - 25) % 70);
*(array + i * Ndays * PROD + j * PROD + k) = randNumB;
}
}
Thank you jonnin and coder777! I appreciate the help much very much. I spent over 16 hours on this assignment in the past week and this part has been a struggle for me.