Originally Posted by
laserlight
Well, it depends on what he wants... the "random" requirement could be satisfied by picking a winner, then distributing the votes as 168, 166, 166.
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) );
while( i == 1 && i == 2 && i == 3 && i == 4)
{
for(i = 0; i < 501; i++)
{
votes [i] = random ( ) % 4 + 1;
printf("\n %d \n", votes[0]);
}
if(i == 1) {
C_A = C_A + 1;
}
if(i == 2)
{
C_B = C_B + 1;
}
if(i == 3)
{
C_C = C_C + 1;
}
if(i == 4)
{
C_D = C_D + 1;
}
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);
}
So can anyone tell me what's wrong with this code. M keep getting 0 for every candidate ????????!!!!!