NEED HELP WITH BASIC C++ PROGRAM

Hey there guys, just trying to figure out why my code is not working as it should. The end goal is for the user to be able to use -1 as a sentinel which will break my do-while loop. Then it is supposed to load a small table displaying the total number of people who were surveyed and how many times an option was selected (counter). The compiler does not read any errors, but when I use the sentinel (-1) it just asks me if I want to answer again and does not display anything.

Here is the code:

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
  #include <iostream>
using namespace std;

int main()
{
	char again;
	int userchoice;
	
	int hcount = 0, tcount = 0, ncount = 0, mcount = 0;
	
	do
	{
		cout << "Vehicle Make Choice:\n";
		cout << "1. Honda\n";
		cout << "2. Toyota\n";
		cout << "3. Nissan\n";
		cout << "4. Mazda\n";
		cout << "-1. Quit\n";
		cin >> userchoice;
		
		if (userchoice = 1) {
			hcount++;
		}else if (userchoice = 2) {
			tcount++;
		}else if (userchoice = 3) {
		    ncount++;
		}else if (userchoice = 4) {
		    mcount++;
		}else if (userchoice = -1) {
		    cout << "Make \t\t Number of users\n";
		    cout << "Honda \t\t " << hcount << endl;
		    cout << "Toyota \t\t " << tcount << endl;
		    cout << "Nissan \t\t " << ncount << endl;
		    cout << "Mazda \t\t " << mcount << endl;
		}
		
		cout << "Would you like to answer again? (Y/N)";
		cin >> again;
		
	} while (again == 'Y' || again == 'y');

}
	






Last edited on
= is assignment
== is comparison

> why my code is not working as it should
you need to be more descriptive.
you said what the program is supposed to do, but not what's doing.
Topic archived. No new replies allowed.