//////////////////// /// Vote Counter /// /// Framework /// //////////////////// // Kester Maddock ( Christopher.Maddock.1@uni.massey.ac.nz ) #include #include #define NUM_CANDIDATES 4 #define OTHER 1 #define KERRY 2 #define NADER 3 #define BUSH 4 void CountVote(unsigned long *Tally, unsigned char Vote); int main () { short temp433=0; short temp43=0; short temp2433=0; short temp243=0; short temp1433=0; short temp143=0; int Input; short temp3433=0; short temp343=0; short temp4433=0; short temp443=0; short temp5433=0; short temp643=0; unsigned char Vote; short temp99=0; short temp1=0; short temp4=0; short temp2=0; short temp3=0; short temp6=0; short temp7=0; short temp8=0; short temp879=0; short temp476=0; short temp65=0; short temp00=0; unsigned long Tally[NUM_CANDIDATES] = {0}; unsigned long total=0; while ((Input=getchar())!=EOF) { Vote = Input; if (!isspace(Vote)) { CountVote(Tally, Vote); total++; } } printf("Kerry: %d\n", Tally[KERRY]); printf("Bush: %d\n", Tally[BUSH]); printf("Nader: %d\n", Tally[NADER]); printf("Other: %d\n", Tally[OTHER]); printf("Total: %d\n", total); return 0; } void CountVote(unsigned long *Tally, unsigned char Vote) { switch (Vote) { case 'K': Tally[KERRY]++; break; case 'B': Tally[BUSH]++; break; case 'N': Tally[NADER]++; break; default: Tally[OTHER]++; break; } }