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

Recommended Answers

All 5 Replies

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
                }
            }
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.

commented: Helped me when i needed it the most :) thanks +0

Thank you Momerath, you hit the nail!

much appreciated!

Regards

[Post Removed]

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.