int main ()
{
const int NR_VOTING_STATIONS = 4;
int votesForA, votesForB, votesForC, spoiltVotes;
char vote;
//initialise totals
for (int i = 0; i < NR_VOTING_STATIONS; i++)
{
while(vote != 'X')
{
cout << "Enter the candidate that you would like to vote for (A, B, C): ";
cin >> vote;
switch(vote)
{
default:
case 'A': ++votesForA;
break;
case 'B': ++votesForB;
break;
case 'C': ++votesForC;
break;
ive got a problem, i dont know where i made my mistake, but it compiles and everything but when i put in votes for A, and exit, it gives me totals for all votes and not even the right ones, im talking about 1000's. can any1 give advice please?
First of all you need to initialize all of your int variables to 0 before you use them (votesForA etc) or else the compiler doesn't know what to add 1 to when you use ++ and just prints out a random number.
Your second mistake is that the default in the switch statement also needs a break; after it, otherwise it is just going to fall through to the 'A' every time and print out the wrong answer.
I am surprised it is letting you do while(vote != 'X') when vote has not been defined at that point. You will either want to give vote some sort of starting value, or change that section into a do-while loop to fix it.
Thanx for the tips, it just I don't know how to end my while loop, cause it has to end when u press x, and do I need to initialize it before loop or will it matter if I put it in loop, I'm new to c++.