Survey program help

My program is not displaying the amount of votes correctly and I have no idea why. Any help would be nice!

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
  #include <iostream>

using namespace std;
int main() 

{
	
	int i,players,vote,totalwii,totalxbox,totalplay = 0;
	cout << "Welcome to the game console survey" << endl;
	cout << "Enter the total number of participants: ";
	cin >> players;
	
	cout << "THe available consoles are: ";
	cout << "\n1. Nintentdo Wii";
	cout << "\n2. Microsoft X-box one";
	cout << "\n3. Sony Playstation 4" << endl;
	cout << "\nIf you prefer Nintendo Wii, enter 1.";	
	cout << "\nIf you prefer Microsoft X-box one, enter 2.";	
	cout << "\nIf you prefer Sony Playstation 4, enter 3." << endl;
	
	for (i=0 ; i < players ; i++)
	{
		cout << "\nParticipant #" << (i+1) << ", Enter your favourite game console choice: ";
		cin >> vote;
		
		if (vote = 1) 
		{
			totalwii++;
		}
		else if (vote = 2)
		{
			totalxbox++;
		}
		else if (vote = 3)
		{
			totalplay++;
		}
		
	}
	
	
	cout << "Results of the survey ------------------->" << endl;
	cout << totalwii << endl;
	
	return 0;
}
I know that it's only printing the wii results, I set it like that to try and isolate the problem.
In the if-conditions, replace = with ==
Alright I've done that now. I've also carried on with more of my code because I need to have a 1st, 2nd and 3rd scale after the survey is done including ties. I'm getting a compiler error and I'm not sure why.

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

#include <iostream>

using namespace std;
int main() 

{
	
	int i,players,vote,totalwii,totalxbox,totalplay = 0;
	cout << "Welcome to the game console survey" << endl;
	cout << "Enter the total number of participants: ";
	cin >> players;
	
	cout << "THe available consoles are: ";
	cout << "\n1. Nintentdo Wii";
	cout << "\n2. Microsoft X-box one";
	cout << "\n3. Sony Playstation 4" << endl;
	cout << "\nIf you prefer Nintendo Wii, enter 1.";	
	cout << "\nIf you prefer Microsoft X-box one, enter 2.";	
	cout << "\nIf you prefer Sony Playstation 4, enter 3." << endl;
	
	for (i=0 ; i < players ; i++)
	{
		cout << "\nParticipant #" << (i+1) << ", Enter your favourite game console choice: ";
		cin >> vote;
		
		if (vote == 1) 
		{
			totalwii++;
		}
		else if (vote == 2)
		{
			totalxbox++;
		}
		else if (vote == 3)
		{
			totalplay++;
		}
		
	}
	
	cout << "Results of the survey ------------------->" << endl;
	cout << "Total participants: " << players << endl;
	
	if (totalwii > totalxbox) && (totalwii > totalplay) && (totalxbox > totalplay) 
		{
			cout << "Nintento 1st " << totalwii << endl;
			cout << "X-box 2nd " << totalxbox << endl;
			cout << "Sony 3rd " << totalplay << endl;
			cout << "Thanks for your participation :) " << endl;	
		}
	if else (totalwii > totalxbox) && (totalwii > totalplay) && (totalxbox < totalplay) 
		{
			cout << "Nintento 1st " << totalwii << endl;
			cout << "Sony 2nd " << totalplay << endl;
			cout << "X-box 3rd " << totalxbox << endl;
			cout << "Thanks for your participation :) " << endl;	
		}	
	if else (totalwii > totalxbox) && (totalwii > totalplay) && (totalxbox > totalplay) 
		{
			cout << "Nintento 1st " << totalwii << endl;
			cout << "X-box 2nd " << totalxbox << endl;
			cout << "Sony 3rd " << totalplay << endl;
			cout << "Thanks for your participation :) " << endl;		
		}
	if else (totalwii > totalxbox) && (totalwii == totalplay)
		{
			cout << "Nintento 1st " << totalwii << endl;
			cout << "X-box and Sony tied for 2nd " << totalxbox << endl;
			cout << "Thanks for your participation :) " << endl;
		}
	if else (totalxbox > totalwii) && (totalxbox > totalplay) && (totalwii > totalplay) 
		{
			cout << "X-box 1st " << totalxbox << endl;
			cout << "Nintendo 2nd " << totalwii << endl;
			cout << "Sony 3rd " << totalplay << endl;
			cout << "Thanks for your participation :) " << endl;
		}
	if else (totalxbox > totalwii) && (totalxbox > totalplay) && (totalwii < totalplay) 
		{
			cout << "X-box 1st " << totalxbox << endl;
			cout << "Sony 2nd " << totalplay << endl;
			cout << "Nintendo 3rd " << totalwii << endl;
			cout << "Thanks for your participation :) " << endl;
		}
	if else (totalxbox > totalwii) && (totalxbox == totalplay)
		{
			cout << "X-box 1st " << totalxbox << endl;
			cout << "Nintendo and Sony tied for 2nd " << totalwii << endl;
			cout << "Thanks for your participation :) " << endl;
		}
	if else (totalplay > totalxbox) && (totalplay > totalwii) && (totalwii > totalxbox) 
		{
			cout << "Sony 1st " << totalplay << endl;
			cout << "Nintendo 2nd " << totalwii << endl;
			cout << "X-box 3rd " << totalxbox << endl;
			cout << "Thanks for your participation :) " << endl;
		}
	if else (totalplay > totalxbox) && (totalplay > totalwii) && (totalwii < totalxbox) 
		{
			cout << "Sony 1st " << totalplay << endl;
			cout << "X-box 2nd " << totalxbox << endl;
			cout << "NIntendo 3rd " << totalwii << endl;
			cout << "Thanks for your participation :) " << endl;
		}
	if else (totalplay > totalxbox) && (totalplay == totalwii)
		{
			cout << "Sony 1st " << totalplay << endl;
			cout << "Nintendo and X-box tied for 2nd " << totalwii << endl;
			cout << "Thanks for your participation :) " << endl;
		}
	if else (totalplay == totalxbox) && (totalplay == totalwii) && (totalxbox == totalwii)
		{
			cout << "All three received equal votes " << totalplay << endl;
			cout << "Thanks for your participation :) " << endl;
		}

	return 0;
		
}

Last edited on
it should be else if, not if else
Wow, I feel dumb now. I've changed it but I'm still getting an expected identifier before '(' token error. What is causing that? Thanks for you help so far by the way :)
Last edited on
Your if-conditions as a whole need to be surrounded by parenthesis.

change:
if (totalwii > totalxbox) && (totalwii > totalplay) && (totalxbox > totalplay)
to:
if ( (totalwii > totalxbox) && (totalwii > totalplay) && (totalxbox > totalplay) )


Do this for all of them
Last edited on
I've done that and it compiles but the program doesnt recognise a tie or winners or anything. It's not working as intended but it looks like it should.
Topic archived. No new replies allowed.