I have a doozy of a conundrum. Conceptually, I think I know what I need to do. Code-wise, I'm not so sure.
I want to go through the AVAIL_NURSE_W1[]
array (which holds the number that corresponds to which nurse is available on Week_1), generate a random number to decide on a slot in that array (if the slot holds a zero value, then generate another random number and try again), take that number (which is a nurse), and put it into the MONDAY[]
array.
Related-code:
int main() {
int randomNurse();
srand(time_t(NULL));
/*0 = Denise, 1 = Inja, 2 = Jane, 3 = Karen, 4 = Maggie, 5 = Margaret, 6 = MJ, 7 = Queen, 8 = Sherri*/
/*-----WEEKLY_ASSIGNMENT-----*/
int AVAIL_NURSE_W1[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; //holds the numerical values of the nurses that CAN work each week
/*scans in first week*/
for (int column = 0; column < 4; column++) {
for (int num = 0; num < 9; num++) {
if (AVAIL_NURSE_W1[num] == select[0][column])
AVAIL_NURSE_W1[num] = 0;
}
}
/*-----MONDAY-----*/
int MONDAY[5]; //days of the week, number of jobs on a given day
for (int e = 0; e < 5; e++) { //loop for positions on monday
while (MONDAY[e] == 0) {
int temp_assign = randomNurse();
if (AVAIL_NURSE_W1[temp_assign] != 0) { //if the nurse IS available...
MONDAY[e] = AVAIL_NURSE_W1[temp_assign];
AVAIL_NURSE_W1[temp_assign] = 0; //we don't want to repeat nurses
} else {
continue;
}
}
}
return 0;
}
/*function to generate random nurse*/
int randomNurse() {
return rand() % 9; //random number 0-8, to pick nurse
}
My Question:
How do I take care of getting the available nurses from the AVAIL_NURSE_W1[]
array, generate a random number which decides which slot to take a value from, takes that value, stores it in a new array MONDAY[]
; if the value in the AVAIL_NURSE_W1[]
array is a ZERO, then repeat the above process until it's selected a non-zero value; after I've selected a value, I will change the selected value to a ZERO and then go through the loop again.
Desired result
The MONDAY[]
array should contain five non-zero integers. No repeats.
So far, it seems the while
loop condition never changes.
Let me know if there is anything else that needs saying. I hope I've given enough information.
scans in first week
? Where isselect
declared and where is it filled with data? – dreamlax 2 days ago