+ 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.
11 Réponses
+ 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.
+ 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
+ 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.
+ 1
Thank you it worked Out. David Ashton
+ 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))
}
0
Here is my Code :
https://code.sololearn.com/c8A162a922A2
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?
0
Thank you
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))
}
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)
}
}
}