問題
Add up the prices in the cart. If the total is at least discount_threshold, take discount_percent percent off the whole total.
Implement cart_total(prices, discount_threshold, discount_percent).
Input
prices: The item prices. discount_threshold: The total that unlocks the discount. discount_percent: The discount in percent.
Output
Return the amount to pay.
制約
0 ≤ length ≤ 1,000; 0 ≤ each price ≤ 100,000; 0 ≤ discount_percent ≤ 100
例
例 1
入力:
prices = [40, 35, 25]
discount_percent = 10
discount_threshold = 100
期待される出力:
expected = 90.0
入力:
std::vector<long long> prices = {40, 35, 25};
long long discount_percent = 10;
long long discount_threshold = 100;
期待される出力:
double expected = 90.0;
入力:
long[] prices = new long[] {40, 35, 25};
long discount_percent = 10;
long discount_threshold = 100;
期待される出力:
double expected = 90.0;
解説
The total is 100, which reaches the threshold, so 10% off: 90.
例 2
入力:
prices = [20, 30]
discount_percent = 10
discount_threshold = 100
期待される出力:
expected = 50.0
入力:
std::vector<long long> prices = {20, 30};
long long discount_percent = 10;
long long discount_threshold = 100;
期待される出力:
double expected = 50.0;
入力:
long[] prices = new long[] {20, 30};
long discount_percent = 10;
long discount_threshold = 100;
期待される出力:
double expected = 50.0;
解説
The total 50 is below 100, so no discount: 50.
参考資料
この課題はCodeUtility用に調整されています。上記の説明と制約に従ってください。