How to make the program repeat the whole quiz if FAIL

Hello, i'm a newbie and just learning with C++ on Visual Studio 2010. I'm making a quiz for an assignment. I just want to add a loop for which if the answer is correct less than 5 questions they have to repeat the quiz all over again until they pass (which is 5 questions above). I'm not very good with repetition command
so hope you guys can help
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
  // PBL 3.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "stdio.h"



int main()
{
	
	char character;
	int answer1=1;
	int answer2=3;
	int answer3=2;
	int answer4=4;
	int answer5=3;
	int answer6=2;
	int answer7=3;
	int answer8=2;
	int answer9=4;
	int answer10=3;


	int total;
	


	printf("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
	printf("\n\t\tWelcome to The NWS 6 Trivia Quiz!!\n");
	printf("\t\tThe quiz consists of 5 question, \n\t\tfrom general knowledge to mathematical questions..\n");
	printf("\t\tAre you ready to take the Quiz??!(Y/N)\n\n\t\t");
	scanf("%c",&character);
	printf("\n\n+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
	

	if (character=='Y')

	{
		
		printf("\nYeah! Here we go!!\n\n");
		{
	{	printf("\nThe first question are,\nThere are 8 Apples on the table, you take 3. How many do you have ?"); 
		printf("\n1: 3 apples");
		printf("\n2: 4 apples");
		printf("\n3: 5 apples");
		printf("\n4: 6 apples\n\n");
		scanf("%i",&answer1);

			switch(answer1)
		{
			case 1:
				printf("\n\nYess! That's the right answer!\n");
				printf("If you take 3 then you will have 3 apples at your hand!LOL\n");
				answer1=1;

			break;

			default:
				printf("\n\nSike! That's the wrong answer!\n");
				printf("The answer should be 3 apples, as you take 3 of them out of 8 apples ON THE TABLE. Get IT??!!");
				answer1=0;
			
		}
	}
		
	{	printf("\nThe next question!\n\n");
		printf("\n10 birds were in a field. 2 were shot, how many were left?");
		printf("\n1. 5 birds");
		printf("\n2. 4 birds");
		printf("\n3. 2 birds");
		printf("\n4. 8 birds\n\n");
		scanf("%i",&answer2);

			switch(answer2)
			{
			case 3:
				printf("\n\nYess! That's the right answer!\n");
				printf("It will be only 2 birds left, as the others flew away caused by the shot sound!\n");
				answer2=1;

			break;

			default:
				printf("\n\nSike! That's the wrong answer!\n");
				printf("It should be only 2 birds left, as the others flew away caused by the shot sound!\n");
				answer2=0;
				
			}

	}
	{	printf("\nAnd the next question is..\n\n");
		printf("\nTake away the first letter, take away the last letter, then take away all the other letters. What do you have left?");
		printf("\n1. All the letters");
		printf("\n2. The Mailman");
		printf("\n3. Nothing left");
		printf("\n4. The Alphabet\n\n");
		scanf("%i",&answer3);

		switch(answer3)
		{
		case 2:
			printf("\n\nYess! That's the right answer!\n");
			printf("As The Mailman's job is to send letters,\nwhen you take away all the letters, what's left?\nIt is him!\n");
			answer3=1;

			break;

		default:
			printf("\n\nSike! That's the wrong answer!!\n");
			printf("The answer should be The Mailman,\nas his job is to send LETTERS. When you take away all the letters,\nit's only him that is left!");
			answer3=0;
			
		}
	}
	{	printf("\nLet's move on to the next question!!\n\n");
		printf("\nIf you have 4 melons in one hand, and 7 apples in the other - What do you have?");
		printf("\n1. 4 melons and 7 apples");
		printf("\n2. 4 melons in one hand, and 7 apples in the other");
		printf("\n3. It's just impossible, right?");
		printf("\n4. Just a big, big hand\n\n");
		scanf("%i",&answer4);

		switch(answer4)
		{
		case 4:
			printf("\n\nYess! That's the right answer!\n");
			printf("You should have a big hand then!\n\n");
			answer4=1;
			break;

		default:
			printf("\n\nSike! That's the wrong answer!!\n");
			printf("It's still logical, if you have a mother-of-god two big hand!!\n\n");
			answer4=0;
			
		}
	}
	{	printf("\nAnd the next question is a corn!\n");
		printf("\nA box has nine ears of corn in it. A Squirrel carries out three ears a day,\nand yet it takes him nine days to carry out all the corn. WHY?");
		printf("\n1. He just too slow to do that!");
		printf("\n2. The place is too far from the box.");
		printf("\n3. He has 2 ears, so he can carry only 1 ear of corn per day.");
		printf("\n4. He actually got some backup, just don't tell la\n\n");
		scanf("%i",&answer5);

		switch(answer5)
		{
		case 3 :
			printf("\n\nYess! That's the right answer!\n");
			printf("He already has 2 ears(his own ears), so plus 1 ear of corn,\nso it’s said that 3 ears of corn per day!\n");
			answer5=1;
			break;

		default:
			printf("\n\nSike! That's the wrong answer!!\n\n");
			printf("He already has 2 ears(his own ears), so plus 1 ear of corn,\nso it’s said that 3 ears of corn per day!\n");
			answer5=0;
			
		}
	}
	{	printf("\nNext Question!\nWhy do white sheep eat more than black sheep?\n"); 
		printf("\n1: This is just racist");
		printf("\n2: There are more white sheep than black sheep");
		printf("\n3: Black sheep are dieting");
		printf("\n4: Because of their colour\n\n");
		scanf("%i",&answer6);

			switch(answer6)
		{
			case 2:
				printf("\n\nYess! That's the right answer!\n");
				printf("Easy to spot why, as if the white sheep is more in numbers,\nof course they will eat more ! Easy !\n");
				answer6=1;

			break;

			default:
				printf("\n\nSike! That's the wrong answer!\n");
				printf("Easy to spot why, as if the white sheep is more in numbers,\nof course they will eat more ! Easy !\n");
				answer6=0;	
		}
	}	
		{	printf("\nThe seventh question is :\nI have 2 coins in my hand that add up to 60 cents.\nOne of the coins isn’t a 50 cents piece. What are the two coins?\n"); 
			printf("\n1: 30 cents + 30 cents");
			printf("\n2: 20 cents + 40 cents");
			printf("\n3: 50 cents + 10 cents\n\n");
			scanf("%i",&answer7);

			switch(answer7)
		{
			case 3:
				printf("\n\nYess! That's the right answer!\n");
				printf("It should be 50 cents and a 10 cents,\nas the coin that isn't a 50 cents piece is a 10 cents.\nThe other one is the 50 cents!\n");
				answer7=1;

			break;

			default:
				printf("\n\nSike! That's the wrong answer!\n");
				printf("It should be 50 cents and a 10 cents,\nas the coin that isn't a 50 cents piece is a 10 cents.\nThe other one is the 50 cents!\n");
				answer7=0;
			}
		}
		{	printf("\nNext one please!\nYou are participating in a race. You overtake the second.\nWhat position do you finish?\n");
			printf("\n1. First");
			printf("\n2. Second");
			printf("\n3. Third");
			printf("\n4. Last\n\n");
			scanf("%i",&answer8);

			switch (answer8)
			{
			case 2:
				printf("Yess! That's the right answer!!\n");
				printf("This is because you overtake the second and you take his place,\nso you arrived second!!!\n\n");
				answer8=1;
				break;

			default:
				printf("Sike! That's the wrong answer!!\n");
				printf("If you answer that you arrived first, then you are absolutely wrong!!!\nCause you overtake the second and you take his place so you arrived second!!!\n\n");
				answer8=0;
			}
		}
		{	printf("The second-last question!\nThen, if you overtake last, then you arrive at..\n");
			printf("\n1. Second last");
			printf("\n2. Last");
			printf("\n3. Third last");
			printf("\n4. Not possible\n\n");
			scanf("%i",&answer9);

			switch (answer9)
			{
			case 4:
				printf("Yess! That's the right answer!!\n");
				printf("Tell me, how can you overtake the LAST !!!!\n\n");
				answer9=1;
				break;

			default:
				printf("Sike! That's the wrong answer!!\n");
				printf("Tell me, how can you overtake the LAST !!!! The question is wrong!\n\n");
				answer9=0;
			}
		}
		
		total = answer1+answer2+answer3+answer4+answer5+answer7+answer8+answer9+answer10;
		printf("\nYou got %i right!!\n",total);

		if(total<5)
		{
			printf("\n\nSorry, but you FAILED. Please repeat the test in the future..\n\n");
		}
		else
			printf("\n\nCongratulations !! You passed the test!\n\n");
			return 0;
		
		}
		}
	else
		printf("\n\t\tOkay,next time maybe! HaHa!\n\n\t\t");

	

	return 0;
}



I don't know where to put the loop
I'm blank right now
Try putting the body of the quiz in a function. Then put your loop around the call to that function. Hint: The function should return the number of questions answered correctly so the loop can check if the result is >= 5.
and just learning with C++

You're not learning C++. I don't see any C++ code. C, yes. C++, no.
I don't know if this will work as your using C but write a code that says,

if(total>5) {
printf("Congratulations, you've passed!");
}
else if(total<5) {
printf("You must retry the test.");
system("CLS");
=-=-=Then your loop command here =-=-=
}
Topic archived. No new replies allowed.