Simple question, adding counter to Windows Form program.

Oct 13 2013 7:37 PM

Dear everyone,

I have an assignment due for my class and I basically finished it. I am stuck on one thing. I can't for whatever reason add a counter to the code. It keeps giving me an error saying that I can't convert int to string. Please explain where it needs to go and why you put it there.

Here is my code:

 

using

 

System;

using

System.Collections.Generic;

using

System.ComponentModel;

using

System.Data;

using

System.Drawing;

using

System.Linq;

using

System.Text;

using

System.Windows.Forms;

namespace

Lab6B

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

int number;

private void Form1_Load(object sender, EventArgs e)

{

Random generator = new Random();

number = generator.Next(1, 101);

}

private void button1_Click(object sender, EventArgs e)

{

int guess = Convert.ToInt32(Guess.Text);

if (Guess.Text != string.Empty)

{

if (guess < number)

{

Evaluate.Visible =

false;

label2.Visible =

true;

label2.Text =

"Too Low!";

Clear.Visible =

true;

BackColor =

Color.LightSeaGreen;

}

else if (guess > number)

{

Evaluate.Visible =

false;

label2.Visible =

true;

label2.Text =

"Too High!";

Clear.Visible =

true;

BackColor =

Color.SlateBlue;

}

else

{

MessageBox.Show("You are right! It took you {0} guesses.");

}

}

}

private void button2_Click(object sender, EventArgs e)

{

Guess.Text =

"";

Evaluate.Visible =

true;

label2.Visible =

false;

Clear.Visible =

false;

BackColor =

Color.PowderBlue;

}

private void label2_Click(object sender, EventArgs e)

{

}

}

}

 

 

Thanks!


Answers (1)