0

Please tell what is wrong in the following code????

fun shippingCost(amount: Double, international: Boolean): Double { if (international==true){ return((15/100)*amount) if ((15/100)*amount>=50.0){ return (50.0) } } else { if (amount>=75){ return (0.0) } else{ return((1/10)*amount) } } } fun main(args: Array<String>) { val total = readLine()!!.toDouble() val international = readLine()!!.toBoolean() println(shippingCost(total, international)) } Sample case:true,199 Output is 0.0 Which is not correct.

14th Feb 2022, 5:15 PM
KNOWLEDGE & LEARNING
KNOWLEDGE & LEARNING - avatar
4 Respuestas
+ 2
KNOWLEDGE & LEARNING if you want people to use your code, copy it into the code playground and share it here.
14th Feb 2022, 7:48 PM
Ausgrindtube
Ausgrindtube - avatar
+ 1
You need to use floats to avoid losing decimals in calculations. 0.1,0.15 Also, you should return 50.0 before other value
14th Feb 2022, 5:29 PM
Simba
Simba - avatar
0
fun shippingCost(amount: Double, international: Boolean): Double { var fee : Double = 0.0 if (international==true) { fee = 0.15 * amount if (fee>50) fee=50.0 } else { if (amount<75) { fee = 0.10 * amount } } return fee }
14th Feb 2022, 5:28 PM
SoloProg
SoloProg - avatar
0
Please try to run the code before suggesting a solution.
14th Feb 2022, 5:33 PM
KNOWLEDGE & LEARNING
KNOWLEDGE & LEARNING - avatar