Create an array of questions and use the random number as an index for the array.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
>but i still don't know how to use array
So use a series of if statements, do you know how to use those? :rolleyes:
int r = rand() % N;
if ( r == 0 )
/* First question */
else if ( r == 1 )
/* Second question */
...
else if ( r == N - 1 )
/* Nth question */
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
Call rand every time you want a random number. If you only get one random number then you'll always have the same question. You would think this would be obvious. I guess I just expect too much from other people.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
#include <stdio.h>
#include <stdlib.h>
int main()
{
int N = 3,counter,i;
for(i=0;i<10;i++)
{
int r = rand() % N;
if(r==0) {
printf("2*2=\na)4 b)2 c)3 d)5\n");
if(getchar()=='a')
counter++;
}
else if(r==1) {
printf("2*5=\na)3 b)10 c)4 d)2\n");
if(getchar()=='b')
counter++;
}
else if(r==2) {
printf("2*9=\na)3 b)10 c)18 d)2\n");
if(getchar()=='c')
counter++;
}
getchar();
}
printf("your score is %d\n", counter);
return 0;
}
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
>and sorry for inconvenience....
No, it's my fault. I didn't look closely enough at the code to see all of your problems. If I had things would have gone much more quickly, and for that I appologize.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401