just learning about loops, can't get this one to work

I was out sick last week when they covered loops, and we were tasked to edit last weeks assignment to include one. I went through the lecture code he posted and tried to include one but I can't get it to work. it's a quiz, and I'm keeping track of correct answers. the code is supposed to loop back to question 1 if they do not get all 5 correct. any 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
  #include <iostream>



using namespace std;

int main()
{
	int a = 0;
	int Q1 = 3;
	int Q1in = 0;
	int Q2 = 4;
	int Q2in = 0;
	int Q3 = 2;
	int Q3in = 0;
	int Q4 = 4;
	int Q4in = 0;
	int Q5 = 1;
	int Q5in = 0;
	
	
	do{
	
		a = 0; 
		
		cout << "Welcome to the trivia game! I'm your host, the windows command window! Are you ready? (please input the number next to the multiple choice question)" << endl;
	cout << "First question : What programming language am i written in?" << endl; 
	cout << "1. Python      2. C#    3. C++    4. Javascript" << endl;
	cin >> Q1in;
	
	
		if (Q1in == Q1)
		{
			cout << "congrats, you're right!" << endl;
			a = a + 1;
		}
		else
		{
			cout << "Oh, thats not quite right" << endl;
		}

		cout << "Next Question! What is the correct operator for a cout command?" << endl;
		cout << "1. >>    2. ^^    3. ::    4. <<" << endl;
		cin >> Q2in;

		if (Q2in == Q2)
		{
			cout << "Congrats, you're right!" << endl;
			a = a + 1;
		}
		else
		{
			cout << "Oh, thats not quite right" << endl;
		}

		cout << "Third Question! What is the coding library that allows you to use setprecision in C++?" << endl;
		cout << "1.ctime    2.iomanip    3.string    4.iostream" << endl;
		cin >> Q3in;

		if (Q3in == Q3)
		{
			cout << "Congrats, you're right!" << endl;
			a = a + 1;
		}
		else
		{
			cout << "Oh, thats not quite right" << endl;
		}

		cout << "Question number 4! almost there! which of these commands can be used as an alternative to if()?" << endl;
		cout << "1.cout    2.break    3.setprecision    4.switch" << endl;
		cin >> Q4in;
		if (Q4in == Q4)
		{
			cout << "Congrats, you're right!" << endl;
			a = a + 1;
		}
		else
		{
			cout << "Oh, thats not quite right" << endl;
		}


		cout << "final question! This quiz is a masterful example of coding and belongs in a museum" << endl;
		cout << "1. Absolutley!    2.No way!    3.You wish!    4.It was bad" << endl;
		cin >> Q5in;
		if (Q5in == Q5)
		{
			cout << "Why thank you, that's very kind" << endl;
			a = a + 1;
		}
		else
		{
			cout << "You're still correct because opinions can't be wrong! Still hurts though. I'll remember this" << endl;
			a = a + 1;
		}

		cout << "you got " << a << " out of 5 correct!" << endl;
	} while (a != 5);

	if(a==5)
	{
		cout << "WOW. you got all five questions correct!! someone should give you a medal or something" << endl;
	}


	return 0;
}
Last edited on
Dunno - it seems to work fine here.
Just looking over it, it all looks fine to me. Ran it with the option on this site and works as expected. What's happening with your end when you try to run it?
Topic archived. No new replies allowed.