1
Reply

C# GUI code help

Michael Knight

Michael Knight

Jul 4 2013 2:02 AM
1.7k
I have the same GUI Form to create as someone else on this forum had. I have tried their code and added some more to it but still have no luck making it work. I am pasting the assignment instructions and the code they have along with my additional added code. I need some kind of guidance please.

 

Create a Form that contains two randomly generated arrays, each containing 100 numbers. Include two buttons labeled initially 1 and 2. Starting with position 0 in each array, ask the user to guess which of the two arrays contains the higher number and to click one of the two buttons to indicate the guess. After each button click, the program displays the values of the two compared numbers, as well as running counts of the number of correct and incorrect guesses. After making a guess, disable the buttons while the user views the results. Require the user to click a 'Next' button the user can make another guess using the next two array values. If the user makes more than 100 guesses, the program should reset the array subscript to zero, so that the comparison can start over. But continue to keep a running score.

 

namespace PickLarger
{
    public partial class Form1 : Form
    {
        int[] array1 = new int[100];
    int[] array2 = new int[100];
    Random randomObject = new Random();

    private void fillArray(int[] arrayToFill)
    {

        for (int i = 0; i < arrayToFill.Length; i++)
        {

        }
    }
    
    

        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
        }
        class click
        {
            public static int buttonClick = 0;
        }
        public int totalClicks()
        {
            int total = 0;

            for (total = 0; total <= 100; total++)
            {
                total++;
                MessageBox.Show("" + total);
            }
            return total;
        }
        public int getRandomNumberbtn1()
        {
            //Finds random number between 1 and 100

            Random number = new Random();

            int randomNumberbtn1 = number.Next(0, 100);
            return randomNumberbtn1;
        }
        public int getRandomNumberbtn2()
        {
            //Finds random number between 0 and 100

            Random number = new Random();

            int randomNumberbtn2 = number.Next(0, 100);
            return randomNumberbtn2;
        }
        private void btn1_Click(object sender, EventArgs e)
        {
            click.buttonClick++;// Counting button clicks

            int r1 = getRandomNumberbtn1();
            MessageBox.Show("You chose Button One which equals: ");
            int r2 = getRandomNumberbtn2();
            MessageBox.Show("Button Two's random Number is: ");
            int highNo;
            if (r1 > r2)
            {
                highNo = r1;
                MessageBox.Show("Number Correct:" + highNo);
            }
            else
            {
                highNo = r2;
                MessageBox.Show("Number i=Incorrect");
            }
            MessageBox.Show("You have clicked a button: " + click.buttonClick + " Times");//Displaying button click count
            }
        private void btn2_Click(object sender, EventArgs e)
        {
            click.buttonClick++;//Counting button clicks

            int r1 = getRandomNumberbtn1();
            MessageBox.Show("Button One's randon Number is: ");
            int r2 = getRandomNumberbtn2();
            MessageBox.Show("You chose Button Two which equals: ");
            int highNo;
            if (r2 > r1)
            {
                highNo = r2;
                MessageBox.Show("Number Correct:" + highNo);
            }
            else
            {
                highNo = r1;
                MessageBox.Show("Number Incorrect");
            }
            MessageBox.Show("You have clicked a button: " + click.buttonClick + "Times");//Displaying button click count
            }
        public void close()
        {
            int i = click.buttonClick;
            for (i = 0; i > 100; i++)
            {
                Application.Exit();    //trying to close the form after button clicks equal more than 100
            }
        }
        private void btnExit_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
    }
}
 

Answers (1)