title: How to convert Double to Int when dividing two Doubles and multiplying the Double quotient by Int?
body: <p>I am working on the program below. How do you calculate <code>totalCostPerMiles = (numMiles / milesPerGallon) * price;</code> when <code>totalCostPerMiles</code> is a <code>int</code>, <code>numMiles</code> and <code>milesPerGallon</code> are <code>doubles</code>, and <code>price</code> is a <code>int</code> to get the calculated value?</p>
  <p>Suppose <code>milesPerGallon = 30;</code>, <code>numMiles = 15;</code>, and <code>price = 400;</code>.</p>
  <p>I need <code>numMiles / milesPerGallon</code> to output <strong>0.5</strong> instead of 0 and <code>totalCostPerMiles</code> to output <strong>200</strong> instead of 0.</p>
  <p>All variables storing measured values must be doubles and all variables storing monetary values must be integers.</p>
  <pre><code>import java.util.Scanner;
  
  public class RoadTrip {
   public static void main(String[] args) {
    
    int price, budgetPrice,
    priceInDollars, priceInCents, priceInDollarsBudget, priceInCentsBudget,
    totalCostPerMiles, dollars, cents;
    
    double milesPerGallon, numMiles, totalMilePerGall;
    
    Scanner stdin = new Scanner(System.in);
    
    milesPerGallon = stdin.nextDouble(); 
    
    numMiles = stdin.nextDouble(); 
    
    price = stdin.nextInt(); 
    
    budgetPrice = stdin.nextInt(); 
    
    
    
    
    totalCostPerMiles = (numMiles / milesPerGallon) * price; //produces error
  
  </code></pre>