[Solved] Q. Can someone help in shipping calculator task in Kotlin? My attempt is below. | SoloLearn: Learn to code for FREE!

+4

[Solved] Q. Can someone help in shipping calculator task in Kotlin? My attempt is below.

fun shippingCost(amount: Double, international: Boolean): Double { if (total<=75) { total*10/100 } while (international==true){ total*15/100{ break(total>=50) } } } fun main(args: Array<String>) { val total = readLine()!!.toDouble() val international = readLine()!!.toBoolean() println(shippingCost(total, international)) }

3/3/2021 12:23:14 PM

I AM S.P.

11 Answers

New Answer

+2

Here is the full runnable code from my solution -> https://code.sololearn.com/cdyDo0Yljw0m/?ref=app

+2

You don't have a variable "total" in your function. The fuction gets it as parameter from the function call in the mainmethod. So you should rename it to "amount" to work with the user input value. Declare a new variable e.g. "costs" which takes the result and don't forget to return your that variable at the end.

+2

Full shorter and clean code https://code.sololearn.com/csTbNS5W2o9t/?ref=app

+2

Paramjit Singh Rana, I've already done the task with the help of Trinity ⚜:)

+1

please resend your full code i don't do it this project

+1

Muhammadaziz Ravshanbekov, even I don't know how to do none are helping..

+1

Thank you so much Trinity ⚜ 😊

+1

fun shippingCost(amount: Double, international: Boolean): Double { var cost = 0.0 if (international) { cost = if (amount * 0.15 > 50) 50.0 else amount * 0.15 } else if (amount < 75) { cost = amount * 0.1 } return cost } fun main(args: Array<String>) { val total = readLine()!!.toDouble() val international = readLine()!!.toBoolean() println(shippingCost(total, international)) }

+1

Thank you so much for your time, Namrata Dattani, but I've done the task.

+1

fun shippingCost(amount: Double, international: Boolean): Double { if(international==false){ if(amount >=75.0) { return 0.0 } else { return amount*0.1 } } else { return if(amount*0.15 >50.0){ return 50.0 } else { amount *0.15 } } } fun main(args: Array<String>) { val total = readLine()!!.toDouble() val international = readLine()!!.toBoolean() println(shippingCost(total, international)) }

0

Paramjit Singh Rana the code is running fine. Put a double value in the first line of the input and a boolean value in second line than hit run. Thank you Shobhit Pandey...you're welcome. I'm happy I could help out. 🙂