title: C++ problems with dividing and cout
body: <p>I am doing an assignment for Computer Science. We have to make a batting average program. I have it working so that it will calculate the hits, outs, singles, etc. but when it comes to making it calculate the batting average, it's coming up with 0.000. I have no clue why, I've done a ton of google searching, tried making the variable double and float, etc. here is the code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;iomanip&gt;
  #include &lt;cstdlib&gt;
  
  using namespace std;
  
  int main(){
  const int MAX_TIMES_AT_BAT = 1000;
  int hits = 0, timesBatted = 0, outs = 0, walks = 0, singles = 0, doubles = 0, triples = 0, homeRuns = 0;
  float battingAverage = 0.0, sluggingPercentage = 0.0;
  
  for(int i = 0; i &lt; MAX_TIMES_AT_BAT; i++){
      int random = rand() % 100 +1;
  
      if(random &gt; 0 &amp;&amp; random &lt;= 35){ 
          outs++;
      }else if(random &gt; 35 &amp;&amp; random &lt;= 51){
          walks++;
      }else if(random &gt; 51 &amp;&amp; random &lt;= 71){
          singles++;
          hits++;
      }else if(random &gt; 71 &amp;&amp; random &lt;= 86){
          doubles++;
          hits++;
      }else if(random &gt; 86 &amp;&amp; random &lt;= 95){
          triples++;
          hits++;
      }else if(random &gt; 95 &amp;&amp; random &lt;= 100){
          homeRuns++;
          hits++;
      }else{
          cout &lt;&lt; "ERROR WITH TESTING RANDOM!!!";
          return(0);
      }
      timesBatted++;
  }
      cout &lt;&lt; timesBatted &lt;&lt; " " &lt;&lt; hits &lt;&lt; " " &lt;&lt; outs &lt;&lt; " " &lt;&lt; walks &lt;&lt; " " &lt;&lt; singles &lt;&lt; " " &lt;&lt; doubles &lt;&lt; " " &lt;&lt; triples &lt;&lt; " " &lt;&lt; homeRuns &lt;&lt; endl;
  
  
  battingAverage = (hits / (timesBatted - walks));
  sluggingPercentage = (singles + doubles * 2 + triples * 3 + homeRuns*4) / (timesBatted - walks);
  
  cout &lt;&lt; fixed &lt;&lt; setprecision(3) &lt;&lt; "Batting Average: " &lt;&lt; battingAverage &lt;&lt; "\nSlugging Percentage: " &lt;&lt; sluggingPercentage &lt;&lt; endl;
  
  
  return 0;
  }
  </code></pre>
  
  <p>Any help would be great! What is going wrong??? I calculated it, and the batting average should be 0.5646 and the slugging percentage should be 1.0937. what its showing is 0.0000, and 1.0000. Thanks in advance!!!</p>