0

How to solve this?

On an eCommerce website, you need to make a shipping cost calculator based on order amount. The store uses the following cost structure: For orders in the US: -$75+ orders have free shipping -orders less than $75 have a shipping fee of 10% of the total order amount For international orders: 15% shipping fee, with a maximum of $50. This means that the max. shipping fee for an intll order is $50 You need to complete the given shippingCost() function, which takes the order amount and a Boolean indicating whether the order is international or not, and returns the shipping cost for that order. The return amount should be a Double. Sample Input: 140.0 Sample Output: 21.0 The order is for $140 and is international. So, the shipping cost would be 15%, which is $21 fun shippingCost(amount: Double, international: Boolean): Double { } fun main(args: Array<String>) { val total = readLine()!!.toDouble() val international = readLine()!!.toBoolean() println(shippingCost(total, international)) }

17th Jul 2021, 12:59 PM
Ehthisham Mohammed
Ehthisham Mohammed - avatar
2 odpowiedzi
0
For order in us , you can calculate fee by doing amount*10/100 and then adding that fee to amount . For international orders you calculate fee the same way by doing amount *15/100 and adding it to amount but this time you need to check if fee will exceed 50$ or not . If it exceeds that set the fee to 50$ .
17th Jul 2021, 1:42 PM
Abhay
Abhay - avatar
+ 1
Thank you so much. I would call this an ideal answer - not giving the exact answer but just giving an outline to figure out syntax on our own - Thanks again
17th Jul 2021, 1:44 PM
Ehthisham Mohammed
Ehthisham Mohammed - avatar