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:
Dear Student ,
As per the requirement submitted above , kindly find the below solution.
Here a new Windows Forms Application in C# is created using Visual Studio 2017 with name "Ass3".This application contains a form with name "Form1.cs".Below are the files associated with form1.
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
{
int secreteNumber = 0;//variable to store secreteNumber
public Form1()
{
InitializeComponent();
}
//secrete button click
private void btnSecrete_Click(object sender, EventArgs e)
{
lblError.Text = "";//clear label
lblHint.Text = "";//clear label
this.Text = "Form1";//set form title
//creating object of Random class
Random random = new Random();
//generate secrete number between min and max range
secreteNumber = random.Next(int.Parse(txtMinRange.Text),
int.Parse(txtMaxRange.Text));
}
//Guess Button click
private void btnGuess_Click(object sender, EventArgs e)
{
lblError.Text = "";//clear label
lblHint.Text = "";//clear label
//taking guess entered by user
int guess = int.Parse(txtGuess.Text);
//checking guess
if (guess < int.Parse(txtMinRange.Text) || guess>
int.Parse(txtMaxRange.Text))
{
//if guess is not in the range
lblError.Text= "You must enter a number between "+ txtMinRange.Text
+ " and "+txtMaxRange.Text+"!";
lblError.ForeColor = Color.Red;//set label color
}
else
{
//checking guess with secrete Number
if(guess> secreteNumber)
{
//if guess is greater than secreteNumber then display message
lblHint.Text = "Higher...";
lblHint.ForeColor = Color.Blue;//set color
}
else if (guess < secreteNumber)
{
//if guess is less than secreteNumber then display message
lblHint.Text = "Lower...";
lblHint.ForeColor = Color.Blue;//set color
}
else if (guess == secreteNumber)
{
//if guess is equal to secreteNumber then display message
lblHint.Text = "You win!";
lblHint.ForeColor = Color.Blue;//set color
//set form title to
this.Text = "----End of Game----";
}
}
}
}
}
======================================================
Output : Run application using F5 and will get the screen as shown below
Screen 1 :
Screen 2:Screen when guess is not in the range
Screen 3:Screen when guess is higher than secrete number
Screen 4:Screen when guess is lower than secrete number
Screen 5:Screen when guess is equal to secrete number
NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.