30 days of code: Day 2

https://www.hackerrank.com/domains/tutorials/30-days-of-code

Today’s code challenge was to come up with the solve function, in order to output the total cost of a meal including the tax and tip.

tip_percent and tax_percet are integers, but no need to convert to a Double?
By dividing the value by 100.0, we are using “Implicit Type Conversion

class Result
{

    /*
     * Complete the 'solve' function below.
     *
     * The function accepts following parameters:
     *  1. DOUBLE meal_cost
     *  2. INTEGER tip_percent
     *  3. INTEGER tax_percent
     */

    public static void solve(double meal_cost, int tip_percent, int tax_percent)
    {
        double tipCost = meal_cost * (tip_percent / 100.0);
        double taxCost = meal_cost * (tax_percent / 100.0);
        double totalCost = meal_cost + tipCost + taxCost;
        Console.WriteLine(Math.Round(totalCost));
    }

}

class Solution
{
    public static void Main(string[] args)
    {
        double meal_cost = Convert.ToDouble(Console.ReadLine().Trim());

        int tip_percent = Convert.ToInt32(Console.ReadLine().Trim());

        int tax_percent = Convert.ToInt32(Console.ReadLine().Trim());

        Result.solve(meal_cost, tip_percent, tax_percent);
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *