locked
Digital combination RRS feed

  • Question

  • i am trying to create a c# program that allows a user to guess numbers required to unlock a safe. the intructions state that;     create three buttons, representing the
    numbers 1, 2 and 3. The user clicks on the buttons, trying to guess the
    correct numbers (e.g. 331121). Use a label to keep track of and display
    the code entered so far. Only once the correct numbers are pressed, the
    program congratulates the user with a suitable message. A button is
    provided to restart.
    Thursday, September 15, 2016 2:36 PM

Answers

  • Hi Bulelwa Dubula,

    According to your description, I written a sample, code below  is for your reference.

    private StringBuilder result = new StringBuilder();
    private void button1_Click(object sender, EventArgs e)
    {
    
        result.Append(button1.Text.ToString());
        result_lbl.Text = result.ToString();
        compare(result.ToString());
    }
    
    private void button2_Click(object sender, EventArgs e)
    {
        result.Append(button2.Text.ToString());
        result_lbl.Text = result.ToString();
        compare(result.ToString());
    }
    
    private void button3_Click(object sender, EventArgs e)
    {
        result.Append(button3.Text.ToString());
        result_lbl.Text = result.ToString();
        compare(result.ToString());
    }
    private void restart_Click(object sender, EventArgs e)
    {
        result.Clear();
        result_lbl.Text = result.ToString();
    }
    private void compare(string r)
    {
        if (result.ToString() == "331121")
            MessageBox.Show("Congratulations");
    }

    I hope this can be helpful.

    Best Regards,
    Li Wang


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, September 19, 2016 7:43 AM

All replies

  • This is the Visual Basic Forum. Perhaps a moderator can move it to the C#.

    Thursday, September 15, 2016 2:39 PM
  • This is the link to the Visual C# forum where you should post your question if a Moderator doesn't move this thread there for you which may take awhile.

    La vida loca

    Thursday, September 15, 2016 3:12 PM
  • This is the link to the Visual C# forum where you should post your question if a Moderator doesn't move this thread there for you which may take awhile.

    La vida loca

    Yes and when Bulla does post in the other forum they should ask a question and show what they have done so far. Not just list instructions for a homework assignment.

    :)

    Thursday, September 15, 2016 3:19 PM
  • Hi Bulelwa Dubula,

    This forum is discussing and asking questions about the Visual Basic programming language, IDE, libraries, samples, and tools. According to your description, it is more related to C#, we'll move the thread to Windows Forms forum for better support.

    Thank you for participating in the forum activities.

    Best Regards,

    Neda Zhang


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.



    • Edited by Neda Zhang Friday, September 16, 2016 5:21 AM
    Friday, September 16, 2016 5:00 AM
  • Hi Bulelwa Dubula,

    According to your description, I written a sample, code below  is for your reference.

    private StringBuilder result = new StringBuilder();
    private void button1_Click(object sender, EventArgs e)
    {
    
        result.Append(button1.Text.ToString());
        result_lbl.Text = result.ToString();
        compare(result.ToString());
    }
    
    private void button2_Click(object sender, EventArgs e)
    {
        result.Append(button2.Text.ToString());
        result_lbl.Text = result.ToString();
        compare(result.ToString());
    }
    
    private void button3_Click(object sender, EventArgs e)
    {
        result.Append(button3.Text.ToString());
        result_lbl.Text = result.ToString();
        compare(result.ToString());
    }
    private void restart_Click(object sender, EventArgs e)
    {
        result.Clear();
        result_lbl.Text = result.ToString();
    }
    private void compare(string r)
    {
        if (result.ToString() == "331121")
            MessageBox.Show("Congratulations");
    }

    I hope this can be helpful.

    Best Regards,
    Li Wang


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, September 19, 2016 7:43 AM