Advertisement
Guest User

Untitled

a guest
Sep 1st, 2014
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.46 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. void Initialize();
  5. void Processvotes();
  6. void printResults();
  7.  
  8. typedef struct info {
  9.     char name[20];
  10.     int votes;
  11. }info;
  12. info electionCandidates[6];
  13.  
  14. int spoiltVotes=0;
  15. FILE *electionInfo;
  16.  
  17. int main()
  18. {
  19.     Initialize();
  20.     Processvotes();
  21.     //printResults();
  22.  
  23.     return 0;
  24. }
  25.  
  26. void Initialize() {
  27.     int i;
  28.  
  29.     for(i=0;i<7;i++){
  30.         electionCandidates[i].votes=0;
  31.         }
  32. }
  33.  
  34. void Processvotes() {
  35.     int i;
  36.     int voteHolder[365];
  37.  
  38.     electionInfo = fopen("elections.txt","r");
  39.     fseek(electionInfo, 0L, SEEK_SET);
  40.  
  41.     for (i=0;i<7;i++){
  42.         fgets(electionCandidates[i].name, 20, electionInfo);
  43.     }
  44.  
  45.     for (i=0;i<365;i++){
  46.         fscanf(electionInfo, "%d", &voteHolder[i]);
  47.         switch(voteHolder[i]){
  48.         case 1:
  49.             electionCandidates[0].votes++;
  50.             break;
  51.         case 2:
  52.             electionCandidates[1].votes++;
  53.             break;
  54.         case 3:
  55.             electionCandidates[2].votes++;
  56.             break;
  57.         case 4:
  58.             electionCandidates[3].votes++;
  59.             break;
  60.         case 5:
  61.             electionCandidates[4].votes++;
  62.             break;
  63.         case 6:
  64.             electionCandidates[5].votes++;
  65.             break;
  66.         case 7:
  67.             electionCandidates[6].votes++;
  68.             break;
  69.         default:
  70.             spoiltVotes++;
  71.             break;
  72.         }
  73.     }
  74. fclose(electionInfo);
  75.  
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement