Originally Posted by
newbi
well its either 1-4
I suggest that you rewrite your program slightly:
Code:
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int main (void)
{
int C_A = 0, C_B = 0, C_C = 0, C_D = 0;
int loop = 0, i = 0, pre = 0;
int votes [500];
srandom( (unsigned) time(NULL) );
for (i = 0; i < 500; i++)
{
votes [i] = random ( ) % 4 + 1;
printf("\n %d \n", votes[i]);
}
if (i == 1)
{
C_A = C_A + 1;
}
else if (i == 2)
{
C_B = C_B + 1;
}
else if (i == 3)
{
C_C = C_C + 1;
}
else if (i == 4)
{
C_D = C_D + 1;
}
else
{
printf("DESPITE CLAIMS TO THE CONTRARY, THE VALUE OF i = %d\n", i);
}
loop = 0;
printf("\n %d \n", C_A);
printf("\n %d \n", C_B);
printf("\n %d \n", C_C);
printf("\n %d \n", C_D);
return (0);
}
Notice my more consistent indentation. Anyway, compile and run your program with my modifications. What do you see?