Lottery Number Random Guessing Program - Looping, Random Numbers, Listboxes in C#. Create a C# windows form that demonstrates the use of looping, combined with random number generation, to see how many attempts it takes your program to generate a random number that matches a user specified winning lottery number.

Be sure to refer to the general programming guidelines listed above. Name your project:

LotteryLoopRandom - Your Name

THINK: Building Blocks get incremental parts of the logic working and then keep adding incremental functionality until you have it all done break it down avoid the 'Big Bang' - avoid the code it all-at-once approach!

This program will allow the user to enter 3 digits of a winning lottery number into 3 individual text boxes. Then the user can click a "I'm Feeling Lucky" button which will start a repetitive cycle (think: looping / think: while) of generating 3 random digits, verifying if the 3 random digits match the 3 winning/entered digits, logging each match attempt in a ListBox control, exiting the loop if a match is found OR exiting the loop if the number of attempts so far is greater than 1,000. Inform the user of the end result: winning or losing, and how many attempts were made/how many loop cycles were executed.

a) Setup 3 Text Boxes to hold the 3 winning/entered numeric digits to be compared; and 3 Label fields to display the 3 random number digits; in your code make sure each winning/entered digit is numeric and is between 0 - 9

b) Add an "I'm Feeling Lucky" Button; upon clicking the button, start a looping process

c) with each execution of the loop: 1) generate a set of 3 random digits; 2) display the 3 random digits in the labels on the form; 3) compare your three random digits to the three winning digits entered by the user; 4) if the 3 random digits DO NOT match the 3 winning digits in the same sequence left to right, then keep looping, up to 1000 times max; 5) if the 3 random digits DO match the 3 winning number digits in the same sequence left to right, then stop looping, change the background color of the random number digits to green

NOTE: if somehow your program 'hangs' / runs indefinitely in Visual Studio, chances are you have an infinite loop situation (bad!); if so, click on the red Visual Studio Stop icon, go back to your code, and figure out why your code is not breaking out of the loop (think: add a break; statement somewhere)

d) Also, while looping, keep track of the running 'history' of what happened after each cycle of the loop, by showing a line in a ListBox control displaying what the random number was and what the winning number was and what the result of the match attempt was, adding one item to the ListBox for each match attempt made. { think: [your listbox control name].Items.Add(.) }

e) Stop looping once 1,000 attempts have been made from a single button click, also stop looping if a match is found before 1,000 attempts were made. After looping, tell the user how many attempts were made and if they were successful or not ( think: MessageBox.Show() ).

f) Include a Clear All button that clears all the textboxes, labels and ListBox. (the Clear button in the example program may not work, but make sure your Clear button does)

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.