using
System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Text;
using
System.Windows.Forms;
namespace
Guess_that_Number
{
public partial class Form1 : Form
{
//Data Declarations section
int Begin,End,MissTry,Guess,range,veryHigh, High, closePos,closeNeg, Low, veryLow;
public Form1()
{
InitializeComponent();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void lblGuess_Click(object sender, EventArgs e)
{
}
private void btnGuess_Click(object sender, EventArgs e)
{
//Local Variable
int random;
//Variable initailizations
veryHigh = random +20;
High = random +10;
closePos = random +5;
closeNeg = random -5;
Low = random -10;
veryLow = random -20;
MissTry =1;
//Counter for missed tries
Random rand = new Random(DateTime.Now.Second);
random = rand.Next(Begin, End);
//Loop below is used to catch invalid input
while (Guess < Begin && Guess > End)
{
txtHint.Text =
"You've entered " + Guess + " which is outside of the guessing range. Try again!";
txtGuess.Clear();
//Clears the txtGuess text box
}
//Loop below is intended to take the user's guess and determine how close
//or far a guess is.
do{
if( Guess == random){
txtHint.Text = Guess +
" is the the correct number!";
}
else if(Guess <= veryHigh && Guess > High){
txtHint.Text=
"Guess is too high. Guess much lower to win.";
txtGuess.Clear();
MissTry++;
}
else if (Guess <= High && Guess > closePos){
txtHint.Text=
"Guess is high. Guess lower to win.";
txtGuess.Clear();
MissTry++;
}
else if(Guess <=closePos && Guess > random){
txtHint.Text=
"Guess is close. Guess a little lower to win!";
txtGuess.Clear();
MissTry++;
}
else if(Guess >=veryLow && Guess < Low){
txtHint.Text=
"Guess is too low. Guess much higher to win!";
txtGuess.Clear();
MissTry++;
}
else if(Guess >=Low && Guess < closeNeg){
txtHint.Text=
"Guess is low. Guess higher to win!";
txtGuess.Clear();
MissTry++;
}
else if (Guess >=closeNeg && Guess < random){
txtHint.Text=
"Guess is close. Guess a little higher to win!";
txtGuess.Clear();
MissTry++;
}
}
while( Guess != random || MissTry < 4);
}
private void txtNum1_TextChanged(object sender, EventArgs e)
{
Begin =
int.Parse(txtNum1.Text); //Converts input in textbox Num1 to an int
}
private void txtNum2_TextChanged(object sender, EventArgs e)
{
End =
int.Parse(txtNum2.Text);
}
private void btnStart_Click(object sender, EventArgs e)
{
txtRange.Text =
"Guess a number between " + Begin + " to " + End; //Displays the 'guessing' range to the user
}
private void txtRange_TextChanged(object sender, EventArgs e)
{
}
private void txtGuess_TextChanged(object sender, EventArgs e)
{
Guess =
int.Parse(txtGuess.Text);
}
private void txtHint_TextChanged(object sender, EventArgs e)
{
}
}
}
Can someone PLEASE tell me why the complier keeps telling me that my " Guess = int.Parse(Guess.Text);", statement is in the incorrect format.