야근안하기 위한 개린이 블로그

[1일1알고리즘] 6일차 Operators 본문

개발/1일1알고리즘

[1일1알고리즘] 6일차 Operators

벨린이 2020. 4. 16. 10:45

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!

음식가격, 팁비율, 세금비율로 총금액을 계산하는 식.

<?php

// Complete the solve function below.
function solve($meal_cost, $tip_percent, $tax_percent) {
    $tip = $meal_cost*($tip_percent/100);
    $tax = $meal_cost*($tax_percent/100);
    $total = $meal_cost+$tip+$tax;
    echo round($total);
}

$stdin = fopen("php://stdin", "r");

fscanf($stdin, "%lf\n", $meal_cost);

fscanf($stdin, "%d\n", $tip_percent);

fscanf($stdin, "%d\n", $tax_percent);

solve($meal_cost, $tip_percent, $tax_percent);

fclose($stdin);

 

아래와같이 한줄로도 가능.

echo round($meal_cost + $meal_cost * $tip_percent / 100 + $meal_cost * $tax_percent /100);
Comments