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.
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...?
void FunctionThatGetsCalledLots()
{
staticbool 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.
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.