I have this code....but generating the random number is not in the right spot, can someone tell me where it goes...this runs with no errors, just doesnt run correctly
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace RandomNumberGuessingGame
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
MessageBox.Show("Welcome to the Random Number Guessing Game");
}
private void guessButton_Click(object sender, EventArgs e)
{
int number;//declare int for random number
Random rand = new Random(); //create object
number = rand.Next(101); //set int number to random number from 1-100
//user has entered guess
int guess;
guess = int.Parse(usersGuessTextBox.Text);
if (guess == number)
{
MessageBox.Show("Congratulations, you guessed it!");
}
else
{
if (guess < number) { MessageBox.Show("Too low, try again!"); }
else { MessageBox.Show("Too high, try again!"); }
}
}
private void exitButton_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace RandomNumberGuessingGame
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
MessageBox.Show("Welcome to the Random Number Guessing Game");
}
private void guessButton_Click(object sender, EventArgs e)
{
int number;//declare int for random number
Random rand = new Random(); //create object
number = rand.Next(101); //set int number to random number from 1-100
//user has entered guess
int guess;
guess = int.Parse(usersGuessTextBox.Text);
if (guess == number)
{
MessageBox.Show("Congratulations, you guessed it!");
}
else
{
if (guess < number) { MessageBox.Show("Too low, try again!"); }
else { MessageBox.Show("Too high, try again!"); }
}
}
private void exitButton_Click(object sender, EventArgs e)
{
this.Close();
}
}
}