title: how do i avoid integer division in c++?
body: <p>This is my code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  const int MAX_LITERS_OF_MILK_PER_CARTON = 3.78;
  
  const double COST_PER_LITER = 0.38;
  
  const double PROFIT_PER_CARTON = 0.27;
  
  int main(void)
   {
      // Write your main here
      int litersOfMilk;
      int numberOfCartonsNeeded;
      double actualNumberOfCartonsNeeded;
      double totalCostOfMilk;
      double totalProfit;
  
  // Get the liters of mild from the user
      cout &lt;&lt; "Enter the amount of milk in liters: ";
      cin &gt;&gt; litersOfMilk;
      cout &lt;&lt; endl;
  
  //Calculate the decimal number of milk cartons needed
  actualNumberOfCartonsNeeded = static_cast&lt;double&gt; (litersOfMilk) / MAX_LITERS_OF_MILK_PER_CARTON;
  
  //Calculate the number of cartons needed
  numberOfCartonsNeeded = static_cast&lt;int&gt; (actualNumberOfCartonsNeeded + 0.5);
  
  //Calculate the total cost of producing the milk today
  totalCostOfMilk = litersOfMilk * COST_PER_LITER;
  
  //Calculate the profit of the milk for today
  totalProfit = litersOfMilk * (PROFIT_PER_CARTON/MAX_LITERS_OF_MILK_PER_CARTON);
  
  //Output the number of cartons needed, the total cost of the milk &amp; the profit to the screen
  cout &lt;&lt; "Number of Cartons Needed: " &lt;&lt; numberOfCartonsNeeded &lt;&lt; endl;
  cout &lt;&lt; "Total Cost to produce " &lt;&lt; litersOfMilk &lt;&lt; " liters: " &lt;&lt; totalCostOfMilk &lt;&lt; endl;
  cout &lt;&lt; "Total Profit to produce " &lt;&lt; litersOfMilk &lt;&lt; " liters: " &lt;&lt; totalProfit &lt;&lt; endl;
  
  
      return 0;
  }
  </code></pre>
  
  <p>When the program runs, every time there is division, it is doing integer division.</p>
  
  <p>For example, the constant MAX_LITERS_OF_MILK_PER_CARTON is defined as 3.78, but when I divide by this constant, it is dividing by 3 instead of dividing by 3.78</p>
  
  <p>How do I fix this?</p>