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

I am trying to learn Visual Basic on my own and I\'m having problems trying to f

ID: 3656647 • Letter: I

Question

I am trying to learn Visual Basic on my own and I'm having problems trying to figure out what to do on a project in the book called Five, Six, Pick-up-sticks. Here is the project: Write a program that allows the user to challenge the computer to a game of pick-up-sticks. Her is how the game works. The user chooses the number of matchsticks (5 to 50) to place in a pile. then, the computer chooses who will go first. At each turn, the contestant can remove one, two, or three matchsticks from the pile. The contestant who chooses the last matchstick loses. The computer should make the user always select from a pile where the number of matchsticks has a remainder of 1 when dived by 4. For instance, if the user initially chooses a number of matchsticks that has a remainder of 1 when divided by 4, then the computer should have the user go first. Otherwise, the computer should go first and remove the proper number of matchsticks. [Note: the remainder when n is divided by 4 is (n Mod 4).] After writing the program, play a few games with the computer and observe that the computer always wins. Thanks in advance for every body's help.

Explanation / Answer

The computer wants to put the user down to 1. So the computer always takes off a number of sticks that will result in leaving a (multiple of 4) + 1. This is so the user will always end up having to move when the number of sticks reaches 5 meaning that he can only get down to 2 leaving 1 for the computer to take off and the user loses. Sticks = remaining sticks on the pile Computer move takes off N = (Sticks-1) mod 4 You might say that this could leave N = 0 but this will never happen since the computer always leaves the user in a (multiple of 4) + 1. He then has to take off at least 1 meaning that the max number of sticks the computer will ever see is a multiple of 4 so that (Sticks-1) mod 4 will always be nonzero. When Sticks is < 5, take off the appropriate number that will leave 1 Public Class Form1 02 Dim title, prompt, Response As String 03 Dim CurrentPhase As Double 04 05 06 07 Private Sub btnRules_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRules.Click 08 MessageBox.Show("Choose A Number Of Sticks To Toss In The Pile From 5 To 50, The Person To Pick Up The Last Stick Is Declared The Loser") 09 End Sub 10 11 Private Sub BtnNewGame_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnNewGame.Click 12 13 14 txtCurrentPhase.Text = CDbl(CurrentPhase) 15 16 17 18 19 20 21 MessageBox.Show("So You Wish To Challenge Me In The Mighty Game Of Pickup Sticks? You Are Either Very Brave Or Very Foolish My Friend") 22 prompt = "Choose The Number Of Sticks You Wish To Throw In The Pile...Not That It Matters" 23 title = "Pick Up Sticks Challenge" 24 25 26 Response = InputBox(prompt, title) 27 Message(Response) 28 29 30 31 32 33 End Sub 34 Sub Message(ByVal response) 35 Dim ReadRules As String 36 37 38 39 40 ReadRules = ("I Suppose You Didn't Read The Rules? Only Numbers 5 Through 50 Are Allowed...Humans") 41 42 If response = (response < 5) Or (response > 50) Then 43 MessageBox.Show(ReadRules, "READ THE RULES!") 44 45 ElseIf response = (response >= 5) Or (response
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