c - Loop to create random numbers, read from existing array, then create new array -- Stuck in While-Loop -


I have the dodgy of a puzzle conceptually, I think I know what I should do. Code-wise, I'm not so sure

I go through the AVAIL_NURSE_W1 [] array (which holds the number that corresponds to which the nurse is available on Week_1 ), In order to decide on a slot in order to generate a random number that array (if the slot has zero values, then generate another random number and try again), take that number (which is a Nurse), and put it in the Monday [] array Received.

Related-code:

  int main () {int randomNurse (); Srand (time_t (zero)); / * 0 = Dennis, 1 = Inja, 2 = Jane, 3 = Karen, 4 = Maggi, 5 = Margaret, 6 = MJ, 7 = Queen, 8 = Sherry * / / * ----- WEEKLY_ASSIGNMENT - - - / * AVAIL_NURSE_W1 [] = {1, 2, 3, 4, 5, 6, 7, 8, 9}; // Nurses that work in the first week for each week / * holds numeric values ​​of the scan (; column & lt; integer column = 0 4; column ++) {(for integer number = 0; number From & lt; 9; number ++) {if (AVAIL_NURSE_W1 [num] == [0] [select column]) AVAIL_NURSE_W1 [num] = 0; }} / * ----- Monday ----- / * Monday Monday [5]; Number of jobs on a particular day for the day of the day (integer E = 0; E & LT; 5; E ++) {// Loop for Monday posts while (Monday [E] == 0) {int Temp_assign = randomNurse (); If (AVAIL_NURSE_W1 [temp_assign]! = 0) {// Nurse is available ... Monday [E] = AVAIL_NURSE_W1 [temp_assign]; AVAIL_NURSE_W1 [temp_assign] = 0; // We do not want nurses to repeat} and (continued); }} 0 return 0; } / * To generate random nurse in the function * / int randomNurse () {return rand ()% 9; // Random Number 0-8, to take a nurse}  

My question:
I have available nurses to AVAIL_NURSE_W1 [] Array generates a random number that decides to accept a slot, takes that value, stores it in a new array in Monday [] ; If the value is zero in the AVAIL_NURSE_W1 [] array, repeat the above process, unless it has been chosen as a non-zero value; After I select a value, I will change the selected value to zero and then go through the loop again.

desired result
Monday [] The array should have five non-zero integers, no repeats.

So far, it seems that while the position of the loop never changes

Tell me if there is a need to say something else. I hope I have given enough information.

Here you can go:

  # include & lt ; Stdio.h & gt; # Include & lt; Stdlib.h & gt; Const char name [9] [10] = {"Dennis", "Inja", "Jane", "Karen", "Maggie", "Margaret", "MJ", "Queen", "Sherry"}; Const four days [5] [10] = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday"}; Int random (nurse); Int main () {srand (time (faucet)); Int day, e, pause, candidate; Int i, j; / * 0 = Dennis, 1 = Inja, 2 = Jane, 3 = Karen, 4 = Maggi, 5 = Margaret, 6 = MJ, 7 = Queen, 8 = Sherry * / / * ----- WEEKLY_ASSIGNMENT - - - / / AVAIL_NURSE_W1 [9] = {1, 1, 1, 1, 1, 1, 1, 1, 1}; // holds the position of each nurse, 1: available 0: unavailable int pos_par_de [5] = {2, 5, 7, 4, 3}; // Number of required nurses per day, Monday: 2 nurse, Tuesday: 5 nurse ... selection of inc. [5] [9]; // Selection of (j = 0; j & lt; 9; j ++) for selected nurses per day (i = 0; i & lt; 5; i ++) [i] [j] = - 1; // -1 is selected for the meaning of a nurse starting all day of the week for // (day & lt; day = 0 5; day ++) // (condition = 0 For every day {for the position & lt; pos_per_day [day]; Pos ++) // Required for that day's position ({Candidate = Random (Nurse);} While (AVAIL_NURSE_W1 [candidate]!); // AVAIL_NURSE_W1 [candidate] = 0; // Do not change his position [day] [pos] = Do not select the candidate; // The appropriate nurse is not available; Fill out the output array (i = 0; i  

Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -