views:

123

answers:

5

program chooses the number to be guessed by selecting an int at random in the range 1-100. The program then displays the following ext in a label:

I have a number between 1 and 100 -- can you guess my number? Please enter your first guess.

A TextBox should be used to input the guess. As each guess is input, the background color should change to red or blue. Red indicates that the user is getting "warmer", blue that the user is getting "colder". A label should display either "Too High" or "Too Low", to help the user zero in on the correct answer. When the user guesses the correct answer, display "Correct!" in a message box, change the Form's background color to green and disable the TextBox. A TextBox (like other controls) can be disabled by setting the control's Enabled property to False. Provide a Button that allows the user to play the game again. When the button is clicked, generate a new random number, change the background to the default color and enable the TextBox.

+2  A: 

Break it up into smaller problems you can get started on.

  • Can you create a textbox and echo the input?
  • Can you generate a random number?
  • Can you test if a given number is greater or less than your chosen number?
wsorenson
+1  A: 

Break the problem into smaller pieces. You need the program to: 1. Ask user question. 2. Take input from user. 3. Process input from user.

StarShip3000
A: 

Do the smallest thing that does something, no matter how uselss, like print("Guess my number"); then build it from there. Try doing it without using GUI components, they can distract you from the solution.

Once you have a working program that can guess a random number, then introduce GUI elements to it.

Kelly French
+4  A: 

You might want to start off by thinking of the structure, breaking everyting down into smaller pieces.

Step one - Identify the requirements

Now you said that you want to create some sort of software, that allowes you to guess on random numbers. So If we break this down into smaller pieces we get the following:

  1. Random number Generator
  2. Amount of guesses
  3. Possibility to post a new guess

These are the minumum requirements, so if we break each step up into even smaller pieces we will get to the final solution pretty quickly ( i will however only provide you with a sufficient amount of information to get your started on your homework ).

Step two - Understanding random

You might want to head over here to read a little about Random numbers in C#, however as you have probably already guessed you need a ranom number generator, i've provided you with two links to ranom generators and information about it which should help you on the way, but to give you a little example here

example

Random generator = new Random();
generator.Next();

Now you have a couple of extra parameters that might come in handy, check the MSDN Guidelines on Ranom, there are methods / constructors that might be of interest which will help you select a ranom number between a and b.

Step three - creating the interface

Now this is where i say godbye to you, you should have sufficient information on how to start the solution and get some data out there. Otherwise I would suggest this resource

Filip Ekberg
A: 

Use an Binary Search Algorithm.

Zote
Erhm... wrong button? o.O
Filip Ekberg
Well, I suppose the person playing the game could use a binary search algorithm to guess the number. But a binary search wouldn't be used in writing the actual game.
Jeff