Please only respond if you can write in VisualBasic!
In this assignment, you are to code a program IN VISUAL BASICthat selects 10 randomnon-repeating positive numbers (the lottery numbers), takes asingle input from the user, and checks theinput with the ten lottery numbers. The user wins if her inputmatches one of the lottery numbers.Create a project titled Lab5 _Lottery. You probably will need todeclare an array intWins of 10 integerelements. Here is what you are most likely going to do:• First, initialize the array intWinsand assigns -1 to each elementof the array.Hint: Make sure that the Array is declared as a class member(public). Array elements are initialized to -1, which is outside of lottery numbers' range, to distinguishelements that have not been given lotterynumbers yet.• Create a loop that iterates over the array and assigns a randompositive non-repeating integernumber 1-99 to each element of the array.Hint: Use the way I already showed you in class for generating arandom number (see the example onCanvas). That is, use the technique we studied earlier to generateappropriate random numbers from 1 to99 and fill the array. Before the selected number is entered intothe array intWins, make sure that the newnumber is not already in the array. If it is already there, selectanother number and ignore the current.The pseudocode for your random numbers generation may be asfollows:declare a variable "number of selected lottery numbers sofar,"initialize this variable to zerowhile (the_number_of_selected_elements is less than the arraysize)select a new random numbersee if this new random number is already in the arrayif the new random number is not in the arrayincrement the number of selected elementsadd the newly selected element to the array• Then you need to ask the user to enter a single number from 1 to99.• Note: if you want to print the generated number just for testingpurposes you can, and it is a goodidea.The pseudocode your main subroutine (could be event form1_Load)should be similar to this:Private Sub frmMain_Load(sender As Object, e As EventArgs) HandlesMyBase.Load‘Assuming that you have already declared an array as a public classmember.‘Declare the variables you need (explained above)‘initialization step, fill the array with -1‘ select 10 non-repeating random numbers and push them to thearrayEnd Sub
‘Later, you need to get user input‘compare user input against lottery numbers and output whether theuser won‘ outputs selected lottery numbersImportant Note: A program that processes each element of the arrayseparately (i.e. accesses all 10elements of the array for assignment or comparison outside a loop)is inefficient and will result in a verypoor grade.
Please only respond if you can write in Visual Basic! In this assignment, you are to code a program IN VISUAL BASIC that
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am