Pages

3/25/2017

Hackerrank Solution For Day 2: Operators

Problem:- Write a Hackerrank Solution For Day 2: Operators or Hacker Rank Solution Program In C++ For " Day 2: Operators " or Hackerrank solution for 30 Days of Code Challenges.

Logic:- Here we go for Day 2: Operators solution. We can solve this problem by taking a simple example. Suppose you are in cafeteria and you order meal after you finish your meal you have to pay some amount of money also assume you are also interested to pay a Tip (extra amount of money almost 15 - 20 percent of your bill), and you also have to pay Tax's so what will be the total amount you paid in cafeteria. This is a problem for that we will take hacker rank example and solve the problem step by step.Check:-Hackerrank Solution For Day 0: Hello, WorldExplanation:- As we are taking hacker rank example so Meal cost is 12 dollar (according to hacker rank) Tip percent 20 and tax percent is 8 so for according to above input our program perform following steps.Step:1 Tip = Mealcost * tip percent / 100Tip = 12 * 20 / 100 = 2.4Step 2:- Tax = mealcost * tax percent / 100Tax = 12 * 8 / 100 = 0.96Step 3:- Total = Mealcost + Tip +Tax.Total = 12 + 2.4 +0.96 = 15.36Total = round(Total) = 15. So final Bill is 15 Dollar paid by customer in cafetaria..Also Check:-Hackerrank Solution For Day Day 1: Data TypesIf you are In INDIA you can take your example in Indian Rupees or you can consider Dollar as a Rupees. There is two way to solve this problem I have written both codes, also check what is the difference between both methods, there is a minor difference. Now copy the colored code and paste into hacker Rank editor and make sure while selecting editor (Always choose C++, not C++14).