In: Computer Science
C#
What to submit:
One zip file named Ass3.zip
This zip must contain one VS 2017 solution named Ass3, which contains one C# Windows Forms App project also named Ass3 and the project contains a default form, Form1.cs and Program.cs.
No change should be made in Program.cs, but your Form1 must be designed and implemented to satisfy the following requirements.
**Do not submit only a single file of the solution or project. The whole solution folder of VS 2017 must be zipped and submitted for grading.
Requirements:
A new windows form application using visual studio with name "Ass3" is created which contains below details.
1.Form1.cs[Design]
2.Form1.cs
//namespace
using System;
using System.Drawing;
using System.Windows.Forms;
//application namespace
namespace Ass3
{
public partial class Form1 : Form
{
//secrete number variable
int secNumber = 0;
//creating object of Random class
Random random = new Random();
public Form1()
{
InitializeComponent();
}
//secrete button click
private void btnSecrete_Click(object sender, EventArgs e)
{
lblDetails.Text = "";//clear label
lblSample.Text = "";//clear label
this.Text = "Form1";//set form title
//generate number between lower and higher number
secNumber = random.Next(int.Parse(txtLower.Text),
int.Parse(txtHigher.Text));
}
//Guess Button click
private void btnGuess_Click(object sender, EventArgs e)
{
lblDetails.Text = "";//clear label
lblSample.Text = "";//clear label
int guess = int.Parse(txtGuessNumber.Text);//guess entered
//checking guess number
if (guess < int.Parse(txtLower.Text) || guess>
int.Parse(txtHigher.Text))
{
//show error if guess is not in the range
lblDetails.Text= "You must enter a number between "+ txtLower.Text
+ " and "+txtHigher.Text+"!";
lblDetails.ForeColor = Color.Red;//set label color
}
else
{
//checking guess with generated random number
if (guess < secNumber)
{
//if guess is lower than generated random number then display
message
lblSample.Text = "Lower...";
lblSample.ForeColor = Color.Blue;//set color
}
else if (guess == secNumber)
{
//if guess is equal to secreteNumber then display message
lblSample.Text = "You win!";
lblSample.ForeColor = Color.Blue;//set color
//set form title to
this.Text = "----End of Game----";
}
else if (guess> secNumber)
{
//if guess is higher than generated random number then display
message
lblSample.Text = "Higher...";
lblSample.ForeColor = Color.Blue;//set color
}
}
}
}
}
====================
Screen 1:When number is not in the range
Screen 2:Screen when guess is lower then the generated number
Screen 3:Screen when guess is higher then the generated number
Screen 4:Screen when guess is equal to generated number