Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace NumberGuessing
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void btnGo_Click(object sender, EventArgs e)
- {
- Random rnd = new Random();
- int randomNumber = rnd.Next(1, 10);
- int theirNumber = Convert.ToInt32(txtGuess.Text);
- string outcome = "";
- if (randomNumber == theirNumber)
- {
- outcome = "Congratulations! \n You guessed correctly. \n I also thought of: " + randomNumber;
- }
- else if (randomNumber > theirNumber)
- {
- outcome = "Your guess is too low. \n I thought of: " + randomNumber;
- }
- else
- {
- outcome = "Your guess is too high. \n I thought of: " + randomNumber;
- }
- lblResult.Text = outcome;
- txtGuess.Text = "";
- txtGuess.Focus();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement