Mega Code Archive

 
Categories / C / Development
 

Tossing coins, rand()

#include <stdio.h> #include <time.h> #include <stdlib.h> int main(void) { int coin = 0; int guess = 0; srand(time(NULL)); coin = rand() % 2; printf("Your call ... 0 = head, 1 = tail: "); scanf("%d", &guess); if(coin == guess) printf("You called it correctly ... !\n"); else printf("No way ... !\n"); return 0; }