Вы находитесь на странице: 1из 2

# CSci 122 - Programming Assignment - Ch.

5
Random Number Guessing Game (30pts)
Create an application (name it "GuessingGame") that generates a random number in the range of 1 through 100 (including both 1 and 100), and asks the user to guess what the number is using an input box. If the user's guess is higher than the random number, the program should display, "Too high, try again." If the user's guess is lower than the random number, the program should display, "Too low, try again." Keep track of each guess in a ListBox that shows both the user's guess and whether it was too high or too low. The program should use a loop that repeats until the user correctly guesses the random number and when the correct number is guessed, the program should display, "Congratulations! You guessed correctly!"

## Form Design (12pts)

1. Determine the proper controls needed on the form; make sure to give a descriptive name to
each control used in your code. (10pts)

2. Make sure the following properties are set for the main form: (1pt) Title should be, "Guessing Game" i. The "Guess" button is set as the form's accept button ii. The "Clear" button is set as the form's cancel button. iii. Make sure to assign the following keyboard access keys to the correct buttons: (1pt) 3. "Guess" --> Alt+g i. "Clear" --> Alt+r ii. "Exit" --> Alt+x iii.

Functionality (10pts)
1. Generate a new random number each time the game's "Guess" button is pressed. (1pt) 2. Use a loop that repeatedly asks the user to guess a number using an input box until the user correctly guesses the random number. (4pts) i. Let the user know if their previous guess was too low or too high. ii. Let the user know when they have guessed the correct number. 3. Keep track of the user's guesses by adding them to a ListBox with the latest/most current guess on top. (4pts) i. Each ListBox item should display the guess as well as whether it was too high or too low. 4. Make sure the "Exit" button closes the form and the "Clear" button clears the ListBox. (1pt)

## Input Validation (3pts)

1. Only allow integer values to be entered for guesses. (3pts)

## Extra Credit (5pts)

Allow the user to specify the range of numbers to guess. So instead of always being a random number from 1-100, let the user set the range. Make sure to use input validation on these values to only allow integers.