/*/////////////////////////////////////////////////////////////////////////*/ /*/ vote counter program /*/ /*/ Input: single character ballots (case does not matter) /*/ /*/ Output: Totals for Kerry ('k'), Bush ('b'), Nader ('n'), and Other /*/ /*/ /*/ /*/ Set verbose=1 to get extra verbiage on output. /*/ /*/ /*/ /*/////////////////////////////////////////////////////////////////////////*/ #include #include #include #define SIZE 256 int Tally[SIZE]={0}; int main ( void ) { int i,j,k,l,m, Input, total, is_big_day, verbose=0; time_t now; struct tm * when; i=j=k=l=m=total=0; /**** GET TEH DATE *******************************************************/ now = time(NULL); when = localtime(&now); if( (j=when->tm_mon) == 10 /** <--- 0=jan, 1=feb, ... 10=nov, 11=dec **/ && (k=when->tm_mday) == 3 && (l=when->tm_year) == 104 ) is_big_day = 1; else is_big_day = 0; if( verbose ) { printf( "Date = %d/%d: ", j+1,k ); if( is_big_day ) printf( "This is the big day!\n" ); else printf( "This is but a simulation of the big day!\n" ); } /**** READ TEH DATA AND STORE IN TEH ARRAY *******************************/ while ((Input=getchar())!=EOF) { if (isspace(Input)) continue; /**** Spaces = invalid/blank ballots ****/ Input = tolower(Input); /**** Convert letters to lower case ]***/ if(Input <= SIZE-1) { if(Input >= 1) { Tally[Input]++; total++;} else { while( Input < 0 ) { Input += SIZE; } Tally[Input]+= 1; total = total+l; } } } if( verbose ) printf( "\n+= RESULTS =+\n\n" ); printf("Kerry: %d\n",Tally['k'] ); printf("Bush: %d\n",Tally['b'] ); printf("Nader: %d\n",Tally['n'] ); printf("Other: %d\n",total-(Tally['b']+Tally['k']+Tally['n']) ); return 0; }