How do you make a section of this program inaccessible, after being run once?

I am making a 20-question quiz. The previous ones I have made make a question able to be re-accessed after they answer it. Is there a way to make a question, or certain sections of the program, inaccessible after they've been run? It's probably really simple, so thanks in advance for your time. I'm not sure if the code I have now is usable, but any criticism is accepted.

string answer[20] = { "Canada","Arizona","Songhai",...and so on}; (answers to the quiz)
bool completed[20] = { false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false};

And when the question is answered, the phrase
completed[0] = true;
and so on through 19 is shown.

But when I look at said phrase, an error pops up and says it must have a pointer-to-object type. Is this easy to fix, or should what I have be completely replaced, or...?

Thanks again!
I often do this:

1
2
3
4
5
6
7
8
9
10
11
12
void FunctionThatGetsCalledLots()
{
    static bool once = true;

    if (once)
    {
        // This code is only called the first time 
        // that FunctionThatGetCalledLots() is called.
    }

    // Other code here
}


For your questions you are on the right track with the bool completed[20];:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
bool AllComplete = false;
while(!AllComplete) // Main loop
{
    // Exit Condition
    AllComplete = true;
    for (int j = 0; j < 20; j++) 
        if(!completed[i])
            AllComplete = false;

    // Try again if the question has been completed.
    int i = rand()%20;
    if (completed[i]) continue;

    // Ask your question here
}


For the pointer-to-object thing, show us the applicable line of code and how the variables are defined. We can help you with that.
Last edited on
@Stewbond
the code inside FunctionThatGetsCalledLots which are supposed to be called once are called each and every time :-)

You may have thought just the opposite of what your code is doing!

1
2
3
4
5
6
7
8
   static bool once = true;

    if (once)
    {
        // This code is only called the first time 
        // that FunctionThatGetCalledLots() is called.
     once = false;
    }


Furthermore, the second while wont work as expected by you!
Last edited on
Well, what I have so far (Stewbond) consists of this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
int main()
{
     int question; //the question number (you choose in any order)
     int completed = 0; //this might or might not have to be here
     int score = 0; //this gradually increases with each correct response
     string answer[20] = //you get it
     bool completed[20] = //you get it
     string response; //the answer the user gives
     //intro text (I won't bore you with this)
     while (completed != 20)
     {
          if (question == 1) //and so forth
          {
               //question and answer
               if (response == answer[0]) //and so forth
              {
                   //text
                   completed++;
                   score++;
                   completed[0] = true; //and so forth
              }
          }
     }
}


I am aware that I am putting a lot of extra work on myself with the if statements, please bear with me on that. (I'm fairly new, and I haven't learned many shortcuts yet.)
I also haven't tried the methods yet, so this post was probably unnecessary.

Also, therockon7throw, thanks for your help too. It's all greatly appreciated.
Last edited on
@therockon7throw, Whoops! Forgot line 7.

Topic archived. No new replies allowed.