Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4066754
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T16:09:59+00:00 2026-05-20T16:09:59+00:00

Hello I`m new with C# and I want to make a simple C# pin

  • 0

Hello
I`m new with C# and I want to make a simple C# pin code program where users could only input 3 times or put in 3 times attempts of pincode and the the program will exit using Application.Exit();

but it seems that the loop is making the MessageBox quite annoying continuously and dont allow users to press or key in button for the next 2 attempts.

Help me pls anyone?

Edited with this but the error of “use of unnasigned local variable of ‘pin'” T_T :

private int _failedAttempts = 0;


    private void btnEtr_Click(object sender, System.EventArgs e)
    {
        int pin;

        if (pin != 21)
        {
            if (pin !=21)
            {
                _failedAttempts++;
                MessageBox.Show ("Fail. " + (3 - _failedAttempts) + " attempts more.", "EPIC FAIL", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                if(_failedAttempts == 3)
                {                       
                    Application.Exit();
                }
            }

        }

        else
        {
            MessageBox.Show ("Welcome. Your pin is CORRECT", "CONGRATULATIONS",MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T16:09:59+00:00Added an answer on May 20, 2026 at 4:09 pm

    Right now you’re basically telling the user that they’ve failed, decreasing the counter, and then telling them they’ve failed again.

    You are not giving them the chance to re-enter the pin number. You need to keep track of the attempts outside of the button click event. Declare a class level variable that will keep track of the attempts.

    e.g.

    private int _failedAttempts = 0;
    

    And change your button click to something like:

    if (pin !=21)
    {
      _failedAttempts++;
      MessageBox.Show ("Fail. " + (3 - _failedAttempts) + " attempts more.", "EPIC FAIL", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
    
       if(_failedAttempts == 3)
       {                       
         Application.Exit();
       }
    }
    

    This lets the user enter the pincode, if it fails, it will display the error message and increase the number of attempts. You should let them enter the pin number again, and let them hit the enter button again. When it hits 3 attempts it will exit.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to make a simple program. Don't really care what it does, actually.
Hello guys I'm using C and GTK+ 2 I want to make a simple
Hello all im new to wordpress and i want to make a portfolio &
Hello every one I am new with servers things. I want to develop program
Hello I'm new to Joomla and I want to change the way an account
Hello everyone I am new to blackberry and I want a textfield that scroll
hello i am little new to all this but i want to know that:
Name: <%= Html.TextBox(txtName, 20, new { @class = hello }) %> I want that
Ok this is a continuation from this question: How to make a simple Hello
Hello iam new to GWT framework. I want to persist my domain objects/entities to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.