Warning: First try to code by your own. If you’re not able to code by your own / if your not able to understand the problem then only read the following code.


Objective:

In this challenge, you’ll work with arithmetic operators. Check out the Tutorial tab for learning materials and an instructional video!


Task:

Given the meal price (base cost of a meal), tip percent (the percentage of the meal price being added as tip), and tax percent (the percentage of the meal price being added as tax) for a meal, find and print the meal’s total cost.

Note: Be sure to use precise values for your calculations, or you may end up with an incorrectly rounded result!


Input Format

There are 3 lines of numeric input:

The first line has a double, mealCost (the cost of the meal before tax and tip). The second line has an integer, tipPercent (the percentage of mealCost being added as tip). The third line has an integer, tax Percent (the percentage of mealCost being added as tax).

Output Format

Print the total meal cost, where totalCost is the rounded integer result of the entire bill ( mealCost with added tax and tip).


Sample Input & Output:


Explanation:

Given:

mealCost 12, tipPercent = 20,

tax Percent = 8

Calculations:

tip = 12 * 20/100 = 2.4

tax = 12 * 8/100 = 0.96

totalCost = mealCost + tip + tax = 12 + 2.4 + 0.96 = 15.36

round(totalCost) = 15

We round totalCost to the nearest dollar

(integer) and then print our result, 15.

Program:

import java.util.Scanner;

public class Arithmetic {
public static void main(String[] args) {
/* Read input */
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();

/* Calculate total cost */
int totalCost = (int) Math.round(mealCost +
mealCost * tipPercent / 100.0 +
mealCost * taxPercent / 100.0);

/* Print output */
System.out.println(“The total meal cost is ” + totalCost + ” dollars.”);
}
}