0

I'm trying to learn Java and came up with this challenge - Arithmetic

My code is as follows:

public class Arithmetic {

public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    double mealCost = scan.nextDouble(); // original meal price
    int tipPercent = scan.nextInt(); // tip percentage
    int taxPercent = scan.nextInt(); // tax percentage
    scan.close();

    // Write your calculation code here.
    double tip = mealCost * (tipPercent / 100);
    double tax = mealCost * (taxPercent/100);
    double totalGeneralCost = mealCost + tip + tax;


    // cast the result of the rounding operation to an int and save it as totalCost 
    int totalCost = (int) Math.round(totalGeneralCost);

    // Print your result
    System.out.println(tax);
}

}

Granted that there was an input, how come my tip variable returns 0? Same goes for the tax variable?

vishnu
  • 730
  • 2
  • 6
  • 26

0 Answers0