Question
Making a bingo game in c# visual studio, windows forms. I made a random populated array, without duplicates, for called numbers. I need to print
Making a bingo game in c# visual studio, windows forms. I made a random populated array, without duplicates, for called numbers. I need to print the next element in the array when the "next" button is clicked that prints after the previously called printed numbers (so 14 additional clicks after the initial click). I see why it is printing all elements at once, but I cannot figure out how make it not do that. Show me code that prints one element at a time and adds it to the previous elements printed? Unsure how to make a call that works when I click the "Next" button or if I need a separate function to increment the array and only print the single array element (added to the list of previously printed) when the next button is clicked. I've only had a few weeks learning c# with little other experience. As the code is now, when I click the next button it doesn't increment beyond called[1], I think b/c each "next" button click is reseting the i variable. Please and thanks! The code I have so far is below:
private void btnNext_Click(object sender, EventArgs e) { //array "called" is global
lblNumCalled.BackColor = Color.Yellow;
int i = 1; if (called == null) { Random rand = new Random(); int randNumber = rand.Next(1, 16); called = Enumerable .Range(1, 15) // number 1 - 15 .OrderBy(x => rand.Next()) // randomly shuffled .Take(15) // we only need 15 .ToArray(); // as an array please. lblNumCalled.Text = Convert.ToString(called[0]); lblListOfCalled.Text = Convert.ToString(called[0]); }
else { for (i = 1; i < called.Length; i++) { lblNumCalled.Text = Convert.ToString(called[i]); lblListOfCalled.Text += " " + called[i]; } } }
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