title: C Programming 'Craps' Game
body: <p>I'm doing a learning task for my C programming course, I've been asked to do the following:</p>
  
  <blockquote>
    <p><strong>Task 2. Craps.</strong></p>
    
    <p>In the game of Craps, a "Pass Line" bet proceeds as follows. Using two six-sided dice,
    the first roll of the dice in a craps round is called the "Come out Roll." The bet
    immediately wins when the come out roll is 7 or 11, and loses when the come out roll is
    2, 3, or 12. If 4, 5, 6, 8, 9, or 10 is rolled on the come out roll, that number becomes "the point." The player keeps rolling the dice until either 7 or the point is rolled. If the point is rolled first, then the player wins the bet. If the player rolls a 7 first, then the player
    loses.</p>
    
    <p>Write a program that plays the game of Craps using the rules stated above so that it
    simulates a game without human input. Instead of asking for a wager, the program
    should just calculate if the player would win or lose. Create a function that simulates
    rolling the two dice and returns the sum. Add a loop so that the program plays 10,000
    games.</p>
    
    <p>Add counters that count how many times the player wins, and how many times
    the player loses. At the end of the 10,000 games, compute the probability of winning, i.e.
    Wins / (Wins + Losses) and output this value. Over the long run, who is going to win
    the most games of Craps, you or the house?</p>
  </blockquote>
  
  <p>Here is what I have written so far:</p>
  
  <pre><code># include &lt;stdio.h&gt;
  # include &lt;stdlib.h&gt;
  # include &lt;time.h&gt;
  
  // Craps Program
  // Written by Kane Charles
  // Lab 2 - Task 2
  
  // 7 or 11 indicates instant win
  // 2, 3 or 12 indicates instant los
  // 4, 5, 6, 8, 9, 10 on first roll becomes "the point"
  // keep rolling dice until either 7 or "the point is rolled"
  //      if "the point" is rolled the player wins
  //      if 7 is rolled then the player loses
  
      int wins = 0, losses = 0;
      int r, i;
      int N = 1, M = 12;
      int randomgenerator();
  
  main(void){
  
      /* initialize random seed: */
    srand (time(NULL));
    /* generate random number 10,000 times: */
    for(i=0; i &lt; 10000 ; i++){
       int r = randomgenerator();
       if (r == 7 || r == 11) {
          wins++;
       }
       else if (r == 2 || r == 3 || r == 12) {
          losses++;
       }
       else if (r == 4 || r == 5 || r == 6 || r == 8 || r == 9 || r == 10) {
          int point = r;
          int temproll;
          int *tr = &amp;temproll;
          do
          {
               *tr = randomgenerator();
  
          }while (temproll != 7 || temproll != point);
  
          if (temproll == 7) {
              losses++;
          }
          else if (temproll == point) {
              wins++;
          }
       }
    }
      printf("Wins\n");
      printf("%d",&amp;wins);
      printf("\nLosses\n");
      printf("%d",&amp;losses);
  }
  
  int randomgenerator(){
      r = M + rand() / (RAND_MAX / (N - M + 1) + 1);
      return r;
  }
  </code></pre>
  
  <p>The program always ends with:</p>
  
  <pre><code>Wins:
  0.000000
  Losses:
  0.000000
  </code></pre>
  
  <p>Whereas it is supposed to show (out of 10000) how many times the program won and how many times it lost. Is anybody able to help me out with this please? I suspect I might need to use pointers instead of <code>wins++</code> and <code>losses++</code> so that the scores are kept globally.</p>
  
  <p>Keep in mind I'm new to a lot of this so any help would be greatly appreciated.</p>