help... Randomizing in c++?

hi i wrote a trivia program but i want to improve it by randomizing the questions in it. but how do i do it? thanks:D

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
main()
{
	int l;
	clrscr();
	gotoxy(30,7);printf("[1] QUESTIONS\n");
	gotoxy(30,9);printf("[2] QUIT\n\n");
	gotoxy(30,13);printf("Choose:  ");
	scanf("%d",&l);
	if(l==1)
	easy();
	else if(l==2)
	exit();
	}
easy()
{
	int x;
	char d[5];
	int i=0;
	char a[]="a";
	char b[]="b";
	char c[]="c";
	for(x=0;x<=3;x++)
	{
	clrscr();
	gotoxy(10,5);printf("Direction: Choose the letter of the correct answer.");
	gotoxy(10,7);printf("1. What two letters are both symbols for 1,000?");
	gotoxy(10,9);printf("%s. K and M.",a);
	gotoxy(10,11);printf("%s. A and B.",b);
	gotoxy(10,13);printf("%s. L and D",c);
	gotoxy(10,15);printf("Answer: ");gets(d);
	if(strcmp(d,a)==0)
	{
	gotoxy(12,20);printf("Correct!!!\n");
	i=i+1;
	gotoxy(12,21);printf("Your score is %d",i);
	x=3;
	getch();
	}
	if(strcmp(d,a)!=0)
	{
	gotoxy(12,20);printf("Wrong!!!\n");
	gotoxy(12,21);printf("Life[%d]",x);
	getch();
	if(x>=3)
	{
	main();
	}
	}
	}
	for(x=1;x<=3;x++)
	{
	clrscr();
	gotoxy(10,7);printf("2. What's short for Binary Digit?");
	gotoxy(10,9);printf("%s. BD.",a);
	gotoxy(10,11);printf("%s. Bit.",b);
	gotoxy(10,13);printf("%s. Digit.",c);
	gotoxy(10,15);printf("Answer: ");gets(d);
	if(strcmp(d,b)==0)

	{
	gotoxy(12,20);printf("Correct!!!\n");
	i=i+1;
	gotoxy(12,21);printf("Your score is %d",i);
	x=3;
	getch();
	}
	else
	{
	gotoxy(12,20);printf("Wrong!!!\n");
	gotoxy(12,21);printf("Life[%d]",x);
	getch();
	if(x>=3)
	{
	main();
	}
	}
	}
	for(x=1;x<=3;x++)
	{
	clrscr();
	gotoxy(10,7);printf("3. What digit did Arab mathematician al-Khwarizmi give to the West\n            around 800 B/B.?");
	gotoxy(10,10);printf("%s. Zero",a);
	gotoxy(10,12);printf("%s. One",b);
	gotoxy(10,14);printf("%s. Two",c);
	gotoxy(10,16);printf("Answer: ");gets(d);
	if(strcmp(d,a)==0)

	{
	gotoxy(12,20);printf("Correct!!!\n");
	i=i+1;
	gotoxy(12,21);printf("Your score is %d",i);
	x=3;
	getch();
	}
	else
	{
	gotoxy(12,20);printf("Wrong!!!\n");
	gotoxy(12,21);printf("Life[%d]",x);
	getch();
	if(x>=3)
	{
	main();
	}
	}
	}
	for(x=1;x<=3;x++)
	{
	clrscr();
	gotoxy(10,7);printf("4. What word describes a number system with a base of two?");
	gotoxy(10,9);printf("%s. Decimal",a);
	gotoxy(10,11);printf("%s. Octal",b);
	gotoxy(10,13);printf("%s. Binary",c);
	gotoxy(10,15);printf("Answer: ");gets(d);
	if(strcmp(d,c)==0)

	{
	gotoxy(12,20);printf("Correct!!!\n");
	i=i+1;
	gotoxy(12,21);printf("Your score is %d",i);
	x=3;
	getch();
	}
	else
	{
	gotoxy(12,20);printf("Wrong!!!\n");
	gotoxy(12,21);printf("Life[%d]",x);
	getch();
	if(x>=3)
	{
	main();
	}
	}
	}
	for(x=1;x<=3;x++)
	{
	clrscr();
	gotoxy(10,7);printf("5. How many equal sides does an icosahedron have?");
	gotoxy(10,9);printf("%s. Ten",a);
	gotoxy(10,11);printf("%s. Twenty",b);
	gotoxy(10,13);printf("%s. Thirty",c);
	gotoxy(10,15);printf("Answer: ");gets(d);
	if(strcmp(d,b)==0)

	{
	gotoxy(12,20);printf("Correct!!!\n");
	i=i+1;
	gotoxy(12,21);printf("Your score is %d",i);
	x=3;
	getch();
	}
	else
	{
	gotoxy(12,20);printf("Wrong!!!\n");
	gotoxy(12,21);printf("Life[%d]",x);
	getch();
	if(x>=3)
	{
	main();
	}
	}
	}

}
rand() returns a random number between 0 and a number RAND_MAX, which differs from system to system but is upwards of 32,000 IIRC.

for random numbers that are different each time you run your program, #include <ctime> and call "srand(time(NULL))" once in your program to "seed" the generator.

For random numbers between 0 and x-1, use "rand() % x".
Topic archived. No new replies allowed.