I'm working on a big project but here I am stucked on a little part of this one. The aim is to make a thing happen with 40% chance, so I make an array of 10 number which consists 4 "1" and 6 "0", if it randoms to "1" then it will happen but however my condition is not working, it always print "abcd" even if it randoms "0". Are there any dumb mistakes in here? The second counter part is to make it happens once every 3 seconds
time_t start, end;
int elapsed;
int array[10] = {1,1,1,1,0,0,0,0,0,0};
time(&start); /* start the timer */
do {
time(&end);
elapsed = difftime(end, start);
gotoxy(1, 15);
printf("Time elapsed: %.1d\n", elapsed);
if(elapsed == 0) continue;
min = elapsed%3;
if(min == 0){
random1 = array[rand() % 9];
//random1 = getrand(1,10);
printf("%d\n", random1);
if(random1 == 1){
printf("abcd");
}
}
}
while (1);
Aucun commentaire:
Enregistrer un commentaire