0

the division always computes the solution to 0. I use multiply or addition and the solution returns correctly.

//get customers's price of food or subtotal
Scanner scan = new Scanner(System.in);
System.out.println("Please enter the cost of the your meal");
double foodPrice = scan.nextDouble();

//get customer's tip percentage
System.out.println("What is the percent you would like to tip your server?");
int tipPercent = scan.nextInt();



//calculate the total
    double totalPrice = foodPrice + tipPercent / 100;



//display the total price of the cutomer's meal
    System.out.println("Your total bill with the tip is $" + totalPrice); 
  • 2
    You're doing int division which will of necessity return an int result. To do double division either the numerator or denominator, or both, must be a double. One solution is to cast the top number to double: `double totalPrice = foodPrice + (double) tipPercent / 100;` or you could declare the denominator to be double: `double totalPrice = foodPrice + tipPercent / 100.0;` – Hovercraft Full Of Eels Feb 03 '23 at 20:14

0 Answers0