Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 공차 슈가크럼블
- 스타벅스
- 프로그래밍
- 존맛
- 신메뉴
- 디스트 용량
- 맛집
- 코딩
- 세션저장
- 알고리즘문제
- postman오류
- 배열
- 공차 주문하는법
- Post Method
- laravel
- PHP문법
- php join 함수
- 라라벨문법
- 알고리즘
- php implode
- 남은용량 확인
- 해커랭크
- 스벅 여름
- 라라벨
- 1일1알고리즘
- df -h
- 솔직후기
- php
- 419 Page Expired
- 공차 추천메뉴
Archives
- Today
- Total
야근안하기 위한 개린이 블로그
[1일1알고리즘] 6일차 Operators 본문
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);
'개발 > 1일1알고리즘' 카테고리의 다른 글
[1일1알고리즘] 5일차 [JavaScript] 프로그래머스 Level1 자릿수 더하기 (0) | 2020.04.14 |
---|---|
[1일1알고리즘] 5일차 A Very Big Sum (0) | 2020.04.13 |
[1일1알고리즘] 4일차 (0) | 2020.04.12 |
[1일1알고리즘] 3일차 배열안에 값 모두 더하기 (0) | 2020.04.08 |
[1일1알고리즘] 2일차 php echo 줄바꿈 (0) | 2020.04.07 |
Comments