/*Copyright ElohimTov LLC*/ /* //Name: ElohimTov Solve Code - Operators - Swift Solution //Problem: HackerRank - 30 Days of Code - Operators //Current File: ElohimTovSolve_Operators.(swift).txt //Compile-able File: ElohimTovSolve_Operators.swift //Date: 02/12/2019 //Tale: ElohimTov Solve's Solution to HackerRank.com's // Operators problem, in Swift programming language. // Problem link at https://elohimtov.com/elohimtov.info. */ import Foundation // Complete the solve function below. let hundred: Double = 100.0 func solve(meal_cost: Double, tip_percent: Int, tax_percent: Int) -> Void { let tip_amount: Double = (meal_cost * Double(tip_percent)) / hundred; let tax_amount: Double = (meal_cost * Double(tax_percent)) / hundred; let total_cost: Double = meal_cost + tip_amount + tax_amount; let rounded_cost: Int = Int(total_cost.rounded()); print(rounded_cost); }//ends func solve /* //CREDIT: The following code till end-of-file were provided by HackerRank.com */ guard let meal_cost = Double((readLine()?.trimmingCharacters(in: .whitespacesAndNewlines))!) else { fatalError("Bad input") } guard let tip_percent = Int((readLine()?.trimmingCharacters(in: .whitespacesAndNewlines))!) else { fatalError("Bad input") } guard let tax_percent = Int((readLine()?.trimmingCharacters(in: .whitespacesAndNewlines))!) else { fatalError("Bad input") } solve(meal_cost: meal_cost, tip_percent: tip_percent, tax_percent: tax_percent) /*Copyright ElohimTov LLC*/