title: Rolling 3 dice n number of times and calculating pair and triplet probability in C
body: <p>Trying to write a C program that simulates 1000 throws of three dice and calculates the probability of 2 or 3 numbers appearing on all 3 dice at once. This is my code and I've been scratching my head for days now and can't figure out what's wrong... Theoretically it should work, but the numbers being printed out are usually around 3000 for the pairs and -(huge number) for the triplets.</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main(void)
  {
      int i,coppia,tris,d1,d2,d3;
      float probCoppia, probTris;
  
      printf(&quot; Rolling 3 dice 1000 times...\n&quot;);
  
      for(i=1; i&lt;=1000; i++){
          int d1=rand()%6+1;
          int d2=rand()%6+1;
          int d3=rand()%6+1;
  
          if(d1==d2 || d1==d3 || d2==d3){
              coppia++;
          }
          else if(d1==d2 &amp;&amp; d1==d3){
              tris++;
          }
      }
  
      probCoppia=coppia*0.1;
      probTris=tris*0.1;
      printf(&quot;Pair probability: %f\nTriplet probability: %f&quot;,probCoppia,probTris);
  
  }
  </code></pre>