/* * Name: Philip Lanxon * Collaborator(s): Abbie Mccourt, Micah * Instructor: * Date: 10/27/06 * Assignment: pgm4 * Description: Take in voter data from a txt document, then output results. */ #include #include int main(void) { int voterid, vote, ted = 0, ron = 0, other = 0, scanResults, totalvotes; FILE *fp; fp = fopen("votingdata.txt", "r"); while (EOF != (scanResults = fscanf(fp, "%d %d", &voterid, &vote))) { if(scanResults < 2) { printf("An error occured reading the file."); break; } switch(vote) { case 1: printf("%d Ted Kulongoski \n", voterid); ++ted; break; case 2: printf("%d Ron Saxton \n", voterid); ++ron; break; default: ++other; break; } } totalvotes = (ted+ron+other); printf("________________________________________\n"); printf("Ted = %d\nRon = %d\nError = %d\nTotal = %d", ted, ron, other, totalvotes); getchar(); system("PAUSE"); return 0; }