i cant end my program!

i cant quit
if i use choice !='q' it will loop
if i use choice =='q' it will end after any other given command
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
  #include<iostream>
#include<string>
using namespace std;
int main()
{
char choice,choice2;
int ca=0,cb=0,cc=0,tv=0;
string sa="FPJ",sb="Roco",sc="GMA";

do
{
cout<<"\t PRESIDENTIAL ELECTIONS\n\n";
cout<<"Candidates \n\n";
cout<<"<A>FPJ\t<B>Roco\t<C>GMA \n";
cout<<"-----------------------\n";
cout<<"Enter <v>vote <r> result and <q> quit : ";
cin>>choice2;
if (choice2=='v')
{	cout<<"Enter your vote:";
	cin>>choice;
	switch(choice)
{
case 'A':
case 'a':
ca++;
break;
case 'B':
case 'b':
cb++;
break;
case 'C':
case 'c':
cc++;
break;
}
}
else if (choice2=='r')
{
cout<<"\t Presidential Elections\n\n";
cout<<"Candidates:"<<"\t results:"<<"\n\n";
cout<<"<A>FPJ : "<<ca<<"\n";
cout<<"<B>Roco : "<<cb<<"\n";
cout<<"<C>GMA : "<<cc<<"\n\n";
tv=ca+cb+cc;
cout<<"Total Votes : "<<tv<<"\n";
//place "and the winner is : <name> here//
}
}while (choice !='q');
	return 0;
}
Try choice2 !='q'
1
2
3
cout<<"Enter <v>vote <r> result and <q> quit : ";
cin >> choice2;
if ( choice ... )

You tell the user to type 'q' into choice2, but then you look it from choice.
Topic archived. No new replies allowed.