Explore BrainMass
Share

Guessing a Number with a Form

This content was STOLEN from BrainMass.com - View the original, and get the already-completed solution here!

Write a Windows Form program to guess against a list of randomly generated numbers.

Create a Form, name it GuessANumber and create a randomly generated array containing 100 integer numbers. See examples for random number generation at the following sites: http://www.dotnetperls.com/random http://www.c-sharpcorner.com/UploadFile/mahesh/RandomNumber11232005010428AM/RandomNumber.aspx

The random number generation for the array will be done in a method both when the array is first populated and when the array needs to be repopulated (requirement 10).

The form will have a textbox in which the user will enter an integer number to match against the next number in the array.

The form will have three buttons labeled Guess, Next Guess (disabled at startup), and Exit GuessANumber.

The form will have a label that contains the text "Place your mouse here for a hint" that will generate a hint about the hidden number when the mouse is passed over the label which will be displayed in a second label as follows:

If the current random number in the array is greater than 3 and less than 96 set the second label text to "It's not <random number + 3>"

Else set the second label text to "It's not <random number - 1>"

Starting with position 0 in each array ask the user to guess the number currently selected from the array, enter it in the textbox and click the Guess button. The number for each guess will be selected from the array in the index order (0 - 99).

When the Guess button is clicked:

The Guess button will be disabled.

The Next Guess button will be enabled.

A label will display a "You Win" message if the number entered in the textbox matches the number from the array or "Sorry - You Lose; the number is: <random number>" if the number does not match the number from the array.

If the numbers match add one to an accumulating correct guess counter and display the number of correct guesses made.

If the numbers do not match, add one to an accumulating incorrect guess counter and display the number of incorrect guesses made.

Disable the hint label.

Set the array index to the next number in the array.

When the Next Guess button is clicked:

The Next Guess button will be disabled.

The Guess button will be enabled.

The win/lose message label will be cleared of text.

The hint label will be enabled.

When the user clicks the Next Guess button, the user can then make another guess and the program will use the next array number from the array.

If the user makes more than 100 guesses, the program should use the randomization method to repopulate the random numbers in the array and reset the array subscript to 0 so the guessing can start over, but continue the running totals.

When the user clicks the Exit GuessANumber button the application will close.

Internal Documentation.

© BrainMass Inc. brainmass.com October 25, 2018, 6:23 am ad1c9bdddf
https://brainmass.com/computer-science/random-number-generation/random-number-generation-windows-program-457785

Attachments

Solution Summary

The Windows Form application is provided as .sln, .suo and .csproj in the attached zip file.

$2.19
See Also This Related BrainMass Solution

Write a C# Windows Form program to pick the larger of randomly generated numbers.

Write a C# Windows Form program to pick the larger of randomly generated numbers.

1. Create a Form that contains two randomly generated parallel arrays, each containing 100 numbers.
2. The random number generation for both arrays will be done in a method, both when the arrays are first populated and when they have to be repopulated.
3. The form will have two buttons labeled 1 and 2 and one button labeled Next.
4. Starting with position 0 in each array, ask the user to guess which of the two arrays contains the higher number and click on one of the two buttons (1 or 2) to enter the guess.
5. Use the following text in a label to prompt the user: Which one will contain the higher number? Make your choice, view your score, then click Next.
6. After each button click, the program displays the values of the two compared numbers.
7. If the button clicked does hide the larger number add 1 to a running counter for right answers; if the button clicked does NOT hide the larger number add 1 to a running counter for wrong answers. Use a label to display the running total of both the right and wrong guesses.
8. After a user clicks a button (1 or 2) for their guess disable the buttons (1 and 2) while the user views the results (running totals).
9. When the user clicks the Next button, the user can then make another guess and the program will use the next two corresponding array numbers from the two parallel arrays.
10. If the user makes more than 100 guesses, the program should use the randomization method to repopulate the random numbers in both arrays and reset the array subscripts to 0 so the comparisons start over, but continue the running totals.

View Full Posting Details