Answer:
In C#
See attachment 1 for program interface
See attachment 2 for complete program source code
Step-by-step explanation:
First, define a function to generate random numbers
int cguess; ---> This declares computer guess as integer
void randomGen() {
Clear both text boxes -- for the computer and the user
textBox1.Text = string.Empty;
textBox2.Text = string.Empty;
Generate a new random number
Random rnd = new Random();
cguess = rnd.Next(1, 101); }
Write the following code segment in the submit button click event
If user guess equals computer guess
if(Convert.ToInt32(textBox2.Text) == cguess) {
Display the computer guess
textBox1.Text = cguess.ToString();
Display a congratulatory message
MessageBox.Show("Congrats!!\\Proceed to new game");
Call the randomGen function
randomGen(); }
If otherwise, print too big or too small, as the case may be
else if (Convert.ToInt32(textBox2.Text) > cguess)
{ MessageBox.Show("Too big")}
else { MessageBox.Show("Too small"); }
Write the following in the form load event. So that the computer starts the game immediately the form loads
randomGen();
Write the following in the new game click event. So that the computer starts begins a new game immediately the new game button is clicked
randomGen();