"Kotlin" > "Functions" > Shipping Calculator | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

"Kotlin" > "Functions" > Shipping Calculator

I am learning kotlin. i am currently at "Kotlin" > "Functions" > "Shipping Calculator" project and my Test Case 5 is failing. can you please provide me some hint, so that i can come forward. thank you for your help and time. waiting for your reply.

13th Mar 2021, 4:40 PM
Malaykumar Ginoya
Malaykumar Ginoya - avatar
11 Answers
+ 3
Can you show what you wrote? Best would be to copy and paste your code into a new Kotlin code in the Playground, then post a link to it here.
13th Mar 2021, 6:55 PM
David Ashton
David Ashton - avatar
+ 2
Malaykumar Ginoya I think your line 11 is way too complicated (and gives the wrong answer). Instead of ((amount.toInt()*10)/100).toDouble() I would just use amount/10 I think that should work. If you feed your old code 55 true you should get 5.5 but the code gives 5.0
14th Mar 2021, 1:13 AM
David Ashton
David Ashton - avatar
+ 2
Abbos Sulaymonov sorry I can't help - it was so long ago that I did it, I can't remember how 🤣. I think I just followed directions. Maybe post this as a question in the Q&A and someone more knowledgeable will see it.
14th Mar 2021, 11:48 AM
David Ashton
David Ashton - avatar
+ 1
Thank you it worked Out. David Ashton
14th Mar 2021, 8:31 AM
Malaykumar Ginoya
Malaykumar Ginoya - avatar
+ 1
Hi guys! I've made the excercise with some help of course. The secret is in: "Defining a variable and working on put a value for it". Here is My Code: fun shippingCost(amount: Double, international: Boolean): Double { var fee = 0.0 if (international == false) { if (amount >= 75){ fee = 0.0 } if (amount < 75){ fee = amount * 0.10 } } else { if (amount * 0.15 > 50){ fee = 50.0 } else { fee = amount * 0.15 } } return fee } fun main(args: Array<String>) { val total = readLine()!!.toDouble() val international = readLine()!!.toBoolean() println(shippingCost(total, international)) }
19th May 2021, 5:37 PM
Klaus Bighi
Klaus Bighi - avatar
13th Mar 2021, 9:23 PM
Malaykumar Ginoya
Malaykumar Ginoya - avatar
0
Hello mr.Ashton! I have a question about connection.I could not connect my Github account to sololearn.I entered the code which I recieved in my e-mail. But I could not Authorize!!! I could not click on "Authorize" button!What should I do to connect both of my accounts?
14th Mar 2021, 9:51 AM
Abbos Sulaymonov
Abbos Sulaymonov - avatar
0
Thank you
14th Mar 2021, 12:05 PM
Abbos Sulaymonov
Abbos Sulaymonov - avatar
0
I hope this will help you:- fun shippingCost(amount: Double, international: Boolean): Double { bval cost: Double if(international == true && amount >0) { if(amount >= 333.33) cost = 50.0 else cost = amount * 0.15 } else if(amount >0) { if(amount >= 75) cost = 0.0 else cost = amount*0.10 } else cost = 0.0 return cost } fun main(args: Array<String>) { val total = readLine()!!.toDouble() val international = readLine()!!.toBoolean() println(shippingCost(total, international)) }
6th Apr 2021, 4:11 AM
Shashi Nirala
Shashi Nirala - avatar
23rd Apr 2021, 4:13 PM
Naga Raju K
0
Here is my solution. (Comments are in Turkish.) fun shippingCost(amount:Double, international:Boolean):Double{ if (international){ if (amount * 0.15 > 50 ){ // uluslararasi siparislerde maksimum kargo bedeli 50 USD return (50.0) } else { // uluslarasi siparislerde kargo bedelinin %15 i kadar ürün bedeli var return (amount * 0.15) } } else{ // 75 dolar üstü kargolar ücretsiz if (amount > 75.0) { return (0.0) } // 75 dolar alti kargolarda siparis miktarınını %10 u kadar kargo bedeli var else { return (amount * 0.10) } } }
12th Oct 2022, 8:36 PM
Gokay BURUC
Gokay BURUC - avatar