Hi!
I am doing program to calculate votes.
its very simple but ..........
up to what I did so far it doesn't want to calculate the first vote.
Please tell me what i am missing?

It's what i did so far.

char choice;
 
  int total, voting_station, votes,spoiltVote, totalA, totalB, totalC, totalD, totalE;
  
  //initialise the five totals and spoilt votes to 0
  totalA = 0 ;
  totalB = 0;
  totalC = 0;
  totalD = 0;
  totalE = 0;
  spoiltVote = 0;
 voting_station = 0;
  
 
  cout << "Enter the number of voting stations: " ;
  cin >> voting_station;
 
  for (int  i= 1; i <= voting_station ; i++)
  {
   cout << endl;
   cout << "VOTING STATION " << i << endl;
   cout << "============== " << endl;
   
       // Ask user for whom he wants to vote first
  cout << "First voter:  For whom do you vote (A, B, C, D or E, X to stop) ? ";
  cin >> choice;
 
  //how to count this vote?      :twisted: 
                     
     //Use the while loop 
  while (choice != 'X' && choice != 'x')
  {
     cout << "Next voter:  For whom do you vote (A, B, C, D or E, X to stop) ? ";
     cin >> choice;
      
     switch ( choice)
     {
     case 'A':
      case 'a':
         totalA ++ ;
         break;

and so on..........

Recommended Answers

All 2 Replies

How about moving the switch statement to the top of the while() loop, and then having the "next voter enter choice" at the end of the loop"? It would work out much better, because the switch statement would evaluate the first choice. Something like this:

for (blah; blah; blah) {

   // ...

   cout << "First voter:  For whom do you vote (A, B, C, D or E, X to stop) ? ";
   cin >> choice;

   while (choice != 'X' && choice != 'x') {

   switch (choice) {

   // ...

   cout << "Next voter:  For whom do you vote (A, B, C, D or E, X to stop) ? ";
   cin >> choice;

How about moving the switch statement to the top of the while() loop, and then having the "next voter enter choice" at the end of the loop"? It would work out much better, because the switch statement would evaluate the first choice. Something like this:

for (blah; blah; blah) {

   // ...

   cout << "First voter:  For whom do you vote (A, B, C, D or E, X to stop) ? ";
   cin >> choice;

   while (choice != 'X' && choice != 'x') {

   switch (choice) {

   // ...

   cout << "Next voter:  For whom do you vote (A, B, C, D or E, X to stop) ? ";
   cin >> choice;

:cool:Thanks a lot for a super fast answer. It works perfect now.
:rolleyes:What can I say, I did another stupid mistake. Now I will remember. :o


You are great. Thanks again!!!!!!!!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.