Question: can you rewrite this code without using break,continue,return inside and outside the loop. Arbitary value / sentenial value cannot be used to control loop. For
can you rewrite this code without using break,continue,return inside and outside the loop. Arbitary value sentenial value cannot be used to control loop. For filling the card with unique numbers, you have to go through the BINGO card column by column rather than row by row
which is what we normally do for D arrays Since the BINGO card has columns, this would be a good place to use a for loop.Repalce with these things
Now, for each column inside the for loop you need to find unique values that fit within the allowed range for that column.
So WHILE you haven't found all get a random number in range, check if you have already gotten it in that column if you
have, throw it out and get another if you haven't, put it in your BINGO card.
So for the
th column, your number needs to be
st column, your number needs to be
nd column, your number needs to be
rd column, your number needs to be
th column, your number needs to be
We talked about generating a random number in a range by shifting the result from rand
To get a value from rand
To get a value from rand
To get a value from rand
To get a value from rand
To get a value from rand
We can rewrite this as
To get a value from rand
To get a value from rand
To get a value from rand
To get a value from rand
To get a value from rand
This can be rewritten as
To get a value from rand
To get a value from rand
To get a value from rand
To get a value from rand
To get a value from rand
So you could use one statement
randx
to get random numbers in range for each column the x in the formula is the column numberindex
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
