Hello, I am having issues with incrementing the counter by 1.

In my quiz, the score must only increment by 1 for each question ONLY if the question is correct.

I have made this work, however when the answer is correct, the user can continually click on the Submit btn on WinForms and it will increment the score by 1 each time, therefore breaking the program.

What I need is:

When the answer is correct it increments (IV DONE THAT)
Now, when it increments ONCE, it must not increment again for that question.

Regards

Without your code it's hard to fix it, but set a boolean to indicate if the counter has been incremented.

Okay, This is what it was like when it kept incrementing while correct,

if (IsCorrect)
                {
                    this.LblScore.Text = (++this.incrementCounter).ToString();
                   
                }
                else
                {
                    //do nothing
                }

And this is what I have tried to do:

bool flag = true;

            while (flag)
            {
                if (IsCorrect)
                {
                    this.LblScore.Text = (++this.incrementCounter).ToString();
                    flag = false;
                }
                else
                {
                    //do nothing
                }
            }

Edited 5 Years Ago by simagen: n/a

bool flag = true;
if (IsCorrect && flag) {
    this.LblScore.Text = (++this.incrementCounter).ToString();
    flag = false;
} else {
   // whatever
}

Reset the flag to true when they move to a new question.

Comments
Helped me when i needed it the most :) thanks

Thank you Momerath, you hit the nail!

much appreciated!

Regards

This question has already been answered. Start a new discussion instead.