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 2D arrays). Since the BINGO card has 5 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 5 unique values that fit within the allowed range for that column.
So, WHILE you haven't found all 5, 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
0th column, your number needs to be 1-15
1st column, your number needs to be 16-30
2nd column, your number needs to be 31-45
3rd column, your number needs to be 46-60
4th column, your number needs to be 61-75
We talked about generating a random number in a range by shifting the result from rand()
To get a value from 1-15 rand()%15+1
To get a value from 16-30 rand()%15+16
To get a value from 31-45 rand()%15+31
To get a value from 46-60 rand()%15+46
To get a value from 61-75 rand()%15+61
We can rewrite this as
To get a value from 1-15 rand()%15+1
To get a value from 16-30 rand()%15+15+1
To get a value from 31-45 rand()%15+30+1
To get a value from 46-60 rand()%15+45+1
To get a value from 61-75 rand()%15+60+1
This can be rewritten as
To get a value from 1-15 rand()%15+(15*0)+1
To get a value from 16-30 rand()%15+(15*1)+1
To get a value from 31-45 rand()%15+(15*2)+1
To get a value from 46-60 rand()%15+(15*3)+1
To get a value from 61-75 rand()%15+(15*4)+1
So you could use one statement
rand()%15+(15*x)+1
to get random numbers in range for each column (the x in the formula is the column number/index).

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!