I am trying to practice for arrays and was trying to write a simple code for voting system. User inputs the number for what party theywant to vote and in the end number of votes got by the parties displayed. I am getting the right output for votecounter[1] and votecounter[3] but illogical 6 or 8 digits numbers for votecounter[2] and votecounter[4]. Can u point outthe bug in my code?
#include <stdio.h>
#include <cs50.h>
int main (void)
{
int i, votecounter [5], vote;
for (i = 1; i <= 4; i++)
{
votecounter[i] = 0;
printf ("Cast your vote for the party you want by typing in their number.\n");
printf ("1.PTI\n");
printf ("2.PPP\n");
printf ("3.MQM\n");
printf ("4.PMLN\n");
for ( i = 1; i <=15; i++)
{
vote = GetInt();
if (vote < 1 || vote > 4)
{
printf ("invalid vote.\n");
}
else
votecounter [vote]++;
}
}
printf ("The number of votes for PTI is %i.\n", votecounter[1]);
printf("The number of votes for PPP is %i.\n", votecounter[2]);
printf ("The number of votes for MQM is %i.\n", votecounter[3]);
printf ("The number of votes for PMLN is %i.\n", votecounter[4]);
return 0;
}