Question
This assignment is about simulating a bingo game. Create a 2D array that will be your bingo card. The bingo card will ONLY be 5x5.
This assignment is about simulating a bingo game. Create a 2D array that will be your bingo card. The bingo card will ONLY be 5x5. Make sure your random numbers are truly random between program runs. Use srand() only once and not in a function or loop. Create a function to fill the bingo card with random numbers in the proper ranges. Pass your 2D bingo array to this function to be populated. Be sure to mark the free spot. The B column contains numbers between 1 and 15 The I column contains numbers between 16 and 30 The N column contains numbers between 31 and 45 The G column contains numbers between 46 and 60 The O column contains numbers between 61 and 75 Just a reminder - BINGO numbers MUST be unique. You cannot have the same number in multiple cells of your BINGO card. The rules of BINGO state that every number is unique. Obtaining random numbers using rand() does NOT guarantee that each number is unique YOU must check that each number is unique. If a number has already been used, then get another number. Use the formula we went over in class to obtain numbers in a range do not hardcode every range. Create a function to print the bingo card to the screen. You must match the formatting shown in the sample output. The bingo array must be passed to this function. Create a function to pick a number that has not already been chosen. You will need to use a 1D array to keep track of which numbers between 1 and 75 have been used so that you dont pick numbers that have already been called. If you randomly pick a number that was already called, then pick another. Continue this process until you find a number that has not been previously called. Print the number to the screen along with its corresponding letter. This function should return that value. Do NOT create an array of 75 unique numbers pick one number at a time and ensure it has not already been used. Create a function to determine if a called number exists in the players bingo card. Pass the bingo array and the number to the function. Loop over the array (nested for loops) and, if the number is found in the bingo array, then change the value to 0 to mark it. If the number is found, then this function should return true; otherwise, return false. PLEASE REMEMBER THAT YOU ARE NOT ALLOWED TO USE return TO STOP A LOOP. Create a function to check for a completed row. A completed row is a row in the bingo array that has 0 for every value (we marked our bingo numbers by changing the existing value to zero to indicate that the called number matches one in our bingo card). This function should check every row in the bingo array and return whether or not it found a completed row. Create a function to check for a completed column. A completed column is a column in the bingo array that has 0 for every value (we marked our bingo numbers by changing the existing value to zero to indicate that the called number matches one in our bingo card). This function should check every column in the bingo array and return whether or not it found a completed column. Create a function to check for a completed diagonal. A completed diagonal is a diagonal in the bingo array that has 0 for every value (we marked our bingo numbers by changing the existing value to zero to indicate that the called number matches one in our bingo card). This function should check both diagonals in the bingo array and return whether or not it found a completed diagonal. Add prototypes for the functions at the top of the program. main()
Call function to fill bingo card
Call function to print bingo card to screen
While the player has not won and while there are still numbers to choose from (there are 75 total)
Call a function to pick a number that has not been chosen already this function returns the called number.
Show the player the number (including the B, I, N, G or O) and ask if the player has that number on their bingo card.
If the player answers anything other than something that begins with Y, then reprint the bingo card and increment the count of numbers drawn so far.
/* NOTE : Your code must use this prompt so that your code can easily be tested */
If the player answers something that begins with Y,
then Call a function to determine if the number drawn IS a number from the bingo card. If the function returns false, then print the message about cheating.
If the function returns true, then call a function to check for a completed row and a function to check for a completed column and a function to check for a completed diagonal. If a completed row and/or column and/or diagonal is found, then the player has won and a message should print and the game should end. HINTS
We discussed in class how to get numbers with a range - something you need to do to fill in your BINGO card.
rand() % (end-start+1) + start
Remember that you need to get unique numbers within each range. That formula could give you, for example, a value of 8 twice. To prevent using duplicate values in a single column, you need to keep a 1D array to hold the values you have used - I'll call it the DUP array.
For example, if your random number is 12, then loop through the DUP array and see if 12 has already been used. If it has not, then use it and add it to the DUP array. If it has been used (you find it in DUP), then get a new random number and check if it is a duplicate (need a loop here...).
Make sure you include time.h to use srand(time(0)
Question : How do we get an X in the free space when the BINGO 2D array is int?
Answer : In the video, notice that every time a number is called and it exists in the BINGO card, the number is replaced with an X. Since the 2D array is int, 0 is used to indicate free space OR a called number; therefore, when printing the BINGO card, if an array element is 0, then print 'X'. When filling the BINGO 2d array, you can fill it - every space - using your code and then, at the end of the FillBingoCard function, set element [2][2] to 0.
Question : How do we keep track of what numbers have already been called during the game play if we pick new numbers in function PickNumber()? That function prints the called number to the screen and returns that number
Answer : Since you need to keep an array of called/picked numbers to keep track of what has been called so you don't call the same number twice, that function cannot be created/live in function PickNumber() since it would go away as soon as the function returns. So that array must be created in main. If it is created in main(), then it must be passed to function PickNumber() to be used. You will need to keep track of how many numbers have been added to that array - declare a counter in main, pass it to PickNumber() to be used, and then increment it in main after returning from PickNumber().
Question : what happens if the player says a number is NOT in their card (and it really is)?
Answer : Just like in real BINGO - if you snooze, you lose! If the player says a number is NOT in their card (and it really is), then you do NOT mark it for them. They miss out and that number will not be called again.
You only mark a value in the card if the player says yes AND it exists in the card.
CODING SUGGESTIONS TO GET STARTED
for loop over each cell in column
get rand#
while passes through while loop < counter
if DUP[passes] matches rand#
get new rand#
set passes to 0
else
increment passes
rand# is unique so add to DUP and BINGO
increment counter
set passes to 0
Always check the rubric for what coding elements are required by the assignment.
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.
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started