0

I can not pass one test out of five. Kotlin exam. shipping cost calculator

The store uses the following pricing structure: For US orders: - orders over $75 have free shipping - For orders less than $75, shipping costs are 10% of the total order value. For international orders, shipping charges are 15%, with a maximum of $50. This means that the maximum shipping cost for international orders is $50. You need to extend this shippingCost() fun, which takes the cost of the order and a boolean indicating whether the order is international and returns the shipping cost for that order. The return value must be Double. Code fun shippingCost(amount: Double, international: Boolean): Double{ var cost: Double if(international){ if(amount*0.15>=50.0){ cost=50.0 }else{ cost=amount*0.15 } }else{ if(amount>75.0){ cost=0.0 }else{ cost=75.0*0.1 } } return cost } fun main(args: Array<String>) { val total = readLine()!!.toDouble() val international = readLine()!!.toBoolean() println(shippingCost(total, international)) }

19th Mar 2022, 8:08 PM
Š®Ń€Š° Š”Š¾Š»ŃŃ€
Š®Ń€Š° Š”Š¾Š»ŃŃ€ - avatar
2 Answers
0
fun shippingCost(amount: Double, international: Boolean): Double { var fee : Double = 0.0 if (international) { fee = 0.15 * amount if (fee>50) fee=50.0 } else { if (amount<75) { fee = 0.10 * amount } } return fee } // Good Luck
19th Mar 2022, 9:13 PM
SoloProg
SoloProg - avatar
0
This line is wrong: cost=75.0*0.1 Instead, it should be: cost=amount*0.1 (Why are you always multiplying by 75.0?!) If you fix the above it works fine! Let me know if you have any questions
2nd Apr 2022, 12:49 AM
Raed
Raed - avatar