Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Making a bingo game in c# visual studio, windows forms. I made a random populate

ID: 3592441 • Letter: M

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 the next element in the array when the "next" button is clicked (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 the error of my ways with code please? I've only had a few weeks learning c# with little other experience. 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];
                   
                }
               
            }           
   }

Explanation / Answer

The flaw lies in the for loop in the else section. So that it is printing all the random numbers of the array at once by repeated execution of the loop.

create a goto tag and whenever you clicks the next button create a call to the goto index and write this printing function over there. So when you click the next button it will calls the goto statement and goes there and executes the statement for once and comes back.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote