I've attempted the following problem but I cannot seem to do it without writing tens upon tens of if statements; does anyone know a better way? here is the problem, and below is what i have done (not complete):

Executable file: election.exe
Input file: election.in
Output file: election.out

Suppose the results of an election in a particular county are recorded in a file as a sequence of ones and zeroes, such as:
1000, 0010, 0100, 1000, 1000, 0100, 0001

Each row represents a set of votersí choice for president, according to the following rules:

A 1 in the first position and 0's in the other positions means a vote for Bush. (1000)
A 1 in the second position and 0's in the other positions means a vote for Gore. (0100)
A 1 in the third position and 0's in the other positions means a vote for Nader. (0010)
A 1 in the fourth position and 0's in the other positions means a vote for Buchanan. (0001)
Any vote containing all 0's and no 1's means the voter has left the ballot blank and is therefore invalid. Any vote containing more than one 1 means that the voter has voted for more than one candidate and that is invalid also.

The program should give the total for each candidate and should declare who the winner is. If two or more candidates have tied for first place, the program should output to a file TIE VOTE and the names of candidates that are in first place, in the same order as the candidate positions.
The program should also report the number of invalid ballots.
Both the input and output files must be in the working directory.
(Bush in position 1, Gore in position 2, etc.)
__________________________________________________ __
Sample input:

1010, 0010, 0100, 1000, 1000, 0100, 0101, 0000, 1110
0000, 1010, 0100, 1011, 1111, 1000, 0100, 1000, 0010, 0001, 1000, 0110, 1000
1000, 0100, 0100, 0010, 0001, 0001, 0010, 0001, 1000, 0100, 0010

Corresponding sample output:

Bush has 2, Gore has 2, Nader has 1, and Buchanan has 0 votes.
TIE VOTE, Bush and Gore have same number of votes.
Invalid ballots: 4
Bush has 4, Gore has 2, Nader has 1, and Buchanan has 1 votes.
Bush wins the election.
Invalid ballots: 5
Bush has 2, Gore has 3, Nader has 3, and Buchanan has 3 votes.
TIE VOTE, Gore and Nader and Buchanan have same number of votes.
Invalid ballots: 0

Code:
#include <fstream.h>
#include <apstring.cpp>

void analyze()
{
 int votes=0, who=0;
 if(vote[0]==1)
 {
  who=1;
  votes+=1;
 }
 if(vote[1]==1)
 {
  who=2;
  votes+=1;
 }
 if(vote[2]==1)
 {
  who=3;
  votes+=1;
 }
 if(vote[3]==1)
 {
  who=4;
  votes+=1;
 }

 if(votes<1 || votes>1)
   return 0;

 return who;
}
int bush, gore, nader, buch, invalid;
void output()
{
 ofstream out = ofstream("election.out", ios::app)
 out<<"Bush has "<<bush<<", Gore has "<<gore<<", Nader has "<<nader<<", Buchannan has "<<buch".";
 if(bush>gore && bush>buch && bush>nader)
  {
   out<<"Bush wins the election."<<endl;
   out<<"Invalid votes: "<<invalid;
  }
 else if(gore>buch && gore>nader && gore > bush)
  {
   out<<"Gore wins the election."<<endl;
   out<<"Invalid votes: "<<invalid;
  }
 else if(nader>buch && nader>bush && nader>gore)
  {
   out<<"Nader wins the election."<<endl;
   out<<"Invalid votes: "<<invalid;
  }
 else if(buch>nader && buch>gore && buch>bush)
  {
   out<<"Buchanan wins the election."<<endl;
   out<<"Invalid votes: "<<invalid;
  }
 else
 {
  out<<"TIE VOTE!";
  if(bush==gore || bush==buch || buch==nader)
  {
   out<<"Bush and ";
   if(bush==gore)
   out<<"Gore" 

   

int main()
{
      apstring vote;
      ifstream in;
      in.open("election.in");

      in>>vote;
      while(!in.eof())
      {
      int who;

        who=analyze();
        switch(who)
        {
         case 1:
          bush+=1;
          break;
         case 2:
          gore+=1;
          break;
         case 3:
          nader+=1;
          break;
         case 4:
          buch+=1;
          break;
         case 0:
          invalid+=1;
          break;
        }

      if(vote.length()==4)
        output();
      }

      return 0;
}