Can somebody help me how to random questions in c++?
Here's a part of my program...
for (i = 0; i <= 10; i++)
{
question = int(double(rand())/RAND_MAX*20);
if (question == 1)
{
}
.
.
.
.
.
.
.
if (question == 20)
{
}
}
My professor asked me to put three parts, the easy, average and hard.
That part is for the easy part, the player would have to answer is 10 questions before he can proceed to the next part, which is the average part. The player should not commit more than 3 mistakes or else, the game is over. Another problem is the scores, she also wants me to put the high scores.
How can I put there if(i == 10) then proceed to the average part?
I already tried that but its not working.
Your for loop only goes to i=9. So putting if i==10 will do nothing because it stops at 9.
My suggestion, you need an integer to hold the mistakes.
int mistakes=0;
for (i = 0; i <= 10; i++)
{
question = int(double(rand())/RAND_MAX*20);
if (question == 1)
{
if answered incorrectly mistakes++;
if(mistakes == 3)i=10//Break the loop so no more questions are answered.
}
.
.
.
.
.
.
.
if (question == 20)
{
if answered incorrectly mistakes++;
if(mistakes == 3)i=10//Break the loop so no more questions are answered.
}
}
//Then if you want to go to another level:
if(mistakes<3)//if less than 3 mistakes have already been made
{
//ask the questions again here, like before.
}