Guessing Game Help

Nov 25 2006 11:44 PM
I am new to programming in general. I am trying to complete a project for school and I am running into trouble. I keep putting myself into a loop. Can somebody please help me?

static void Main()
{
   Application.Run(new Form1());
}

private void button2_Click(object sender, System.EventArgs e)
{
   MessageBox.Show("Guess a number between 1 and 100\n"
+ "Red Form = Guess is too HIGH!\n"
+ "Blue Form = Guess is too LOW!");
}

private void button1_Click(object sender, System.EventArgs e)
{
   Random r = new Random();
   int target = r.Next(1,100),
     guess = 0,
     guessTotal = 0,
     high = 0,
     low = 0;
   string invalue = "";

   while(guess != target)
   {
      invalue = this.txtGuess.Text;
      guess = int.Parse(invalue);

      if(guess == target)
        {
           MessageBox.Show("Good Job!\n"
               + "You guessed correctly on the first try\n"
               + "The number was " + target);
        }
        else
        {
           // MessageBox.Show("Wrong Guess.\n" + "Try again");
           guessTotal++;

           if(guess > target)
           {
              //Change Form color red
              MessageBox.Show("Too High");
              high++;
           }
           
           if(guess < target)
           {
              //Change form color blue
              MessageBox.Show("Too Low");
              low++;
            }
       }
  }

Answers (1)