0

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

3
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by CsharpChico
0

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

0

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 by simagen: n/a

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

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

Thank you Momerath, you hit the nail!

much appreciated!

Regards

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.