Type Here to Get Search Results !

Day 2: HackerRank 30 Days Of Code Solution by CodingHumans |Operators |

0

Day 2: Operators

Objective

In this challenge, you'll work with arithmetic operators.

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  being added as tip).
The third line has an integer, taxPercent (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

12.00
20
8

Sample Output

15

Explanation

Given:

mealCost =12, tipPercent =20 , taxPercent =8

Calculations:

tip= 12 x 20/100 =2.4
tax=12 x 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.



Recommended: Please try your approach on your integrated development environment (IDE) first, before moving on to the solution.

Few words from CodingHumans : Don't Just copy paste the solution, try to analyze the problem and solve it without looking by taking the the solution as a hint or a reference . Your understanding of the solution matters.


HAPPY CODING 😁





Solution
( Java )

import java.io.*;
import java.util.*;

public class Solution {
    public static void main(String args[]){
        Scanner sc= new Scanner(System.in);
        double meal_cost=sc.nextDouble();
        int tip_percent=sc.nextInt();
        int tax_percent=sc.nextInt();
    
        double tip=tip_percent *(meal_cost/100);
        double tax=tax_percent *(meal_cost/100);

        int total=(int)Math.round(meal_cost+tip+tax);
        System.out.print(total);
    }
}


If you have any doubts regarding this problem or  need the solution in other programming languages then leave a comment down below . 

Post a Comment

0 Comments

Top Post Ad

Below Post Ad