Advertisement
CodrinH

LOTTO

Feb 12th, 2013
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.95 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. #define RANGE 10
  6. #define BALLS 6
  7.  
  8. int main()
  9. {
  10.  
  11.     int numbers[RANGE];
  12.     int c, ball;
  13.  
  14.     puts("L O T T O\t P I C C K E R");
  15.  
  16.     srand((unsigned)time(NULL));
  17.  
  18.     /* Initialize the array */
  19.  
  20.     for(c=0;c<RANGE;c++)
  21.     {
  22.         numbers[c] = 0;
  23.     }
  24.         printf("Press ENTER to pick this week's number:");
  25.         getchar();
  26.  
  27.     /* draw the numbers */
  28.  
  29.     puts("\nHere they come:\n");
  30.     for(c=0;c<BALLS;c++)
  31.     {
  32.         /* See if a number has been allready been drawn */
  33.         do
  34.         {
  35.             ball = rand() % RANGE; /* Generate the random ball */
  36.         }
  37.         while(numbers[ball]); /* How is this compare made ? */
  38.         /* Number drawn */
  39.         numbers[ball] = 1; /* What is this for ?!?  */
  40.         printf("%2d ", ball+1); /* add 1 to ball so ball won't be zero */
  41.     }
  42.     printf("\n\nGood luck in the drawing!\n");
  43.     return(0);
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement