Create a GUI lottery Game application - Help me
1. Create a GUI lottery game application. Generate three random numbers, each between 1 and 4. Allow the user to guess three numbers. Compare each of the user's guesses to the three random numbers and display a message that includes the user's guess, the randomly deter-mined three-digit number, and the amount of money the user has won as follows:
Matching Numbers Award ($)
Any one matching 10
Two matching 100
Three matching, not in order 1000
Three matching in exact order 10,000
No matches 0
Make certain that your application accommodates repeating digits. For example, if a user guesses 1, 2, and 3, and the randomly generated digits are 1, 1, and 1, do not give the user credit for three correct guesses—just one.
--------------------------------------------------------------------------------------------------------------
Errors : i create this GUI lottery program it just read textbox1.text value and give me only first value 3 time in output.... need a help to fix it ? File Attached for problem understanding.
--------------------------------------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace LotteryGUI
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
// declaring integers
int iNum1 = Convert.ToInt32(textBox1.Text);
int iNum2 = Convert.ToInt32(textBox2.Text);
int iNum3 = Convert.ToInt32(textBox3.Text);
int iCount;
int iGuess;
// declaring constants
const int iBALLS = 3;
const int iMATCHONE = 10;
const int iMATCHTWO = 100;
const int iMATCHTHREE = 1000;
const int iMATCHFOUR = 10000;
// declaring arrays
int[] iSortedNums = new int[3];
int[] iGuesses = new int[3];
int[] iSortedGuesses = new int[3];
// generating random numbers
Random randomnumber = new Random();
iNum1 = randomnumber.Next(1, 5); // gives number between 1 and 4
iNum2 = randomnumber.Next(1, 5);
iNum3 = randomnumber.Next(1, 5);
iSortedNums[0] = iNum1;
iSortedNums[1] = iNum2;
iSortedNums[2] = iNum3;
Array.Sort(iSortedNums); // sort random numbers
for (iCount = 0; iCount < iBALLS; iCount++)
{
//textBox1.Text=("No:" + (iCount + 1) + " Choose your number: ");
iGuess = Convert.ToInt32(textBox1.Text);
while (iGuess < 1 || iGuess > 4)
{
label6.Text = ("You have entered an incorrect number please try again");
textBox1.Text=("\nNo:" + (iCount + 1) + " Choose your number: ");
iGuess = Convert.ToInt32(Console.ReadLine());
}
iGuesses[iCount] = iGuess;
iSortedGuesses[iCount] = iGuess;
}
Array.Sort(iSortedGuesses); // sort the guesses
label4.Text =String.Format ("The random numbers are : " + iNum1 + ", " + iNum2 + ", " + iNum3);
label5.Text = String.Format("The numbers you chose are : " + iGuesses[0] + ", " + iGuesses[1] + ", " + iGuesses[2]);
if (iGuesses[0] == iNum1 && iGuesses[1] == iNum2 && iGuesses[2] == iNum3)
{
MessageBox.Show("you won $" + iMATCHFOUR);
}
else if (iSortedGuesses[0] == iSortedNums[0] && iSortedGuesses[1] == iSortedNums[1]
&& iSortedGuesses[2] == iSortedNums[2])
{
MessageBox.Show("you won $" + iMATCHTHREE);
}
else if ((iGuesses[0] == iNum1 && iGuesses[1] == iNum2) || (iGuesses[1] == iNum2 &&
iGuesses[2] == iNum3))
{
MessageBox.Show("you won $" + iMATCHTWO);
}
else if (iGuesses[0] == iNum1 || iGuesses[1] == iNum2 || iGuesses[2] == iNum3)
{
MessageBox.Show("you won $" + iMATCHONE);
}
else
{
MessageBox.Show("sorry, you didn't win anything");
}
}
}
}