+ 3
Please help me to finish this shopping calculator cuallange
Here is the question You are working on a eCommerce website and need to make a shipping cost calculator based on the order amount. The store uses the following cost structure: For orders in the US: - $75+ orders have free shipping - orders less than $75 have a shipping fee of 10% of the total ord Please see in the comment below what I tried
4 Respuestas
+ 6
You can't assign a variable inside return statement.
Try this
fun shippingCost(amount: Double, international: Boolean): Double {
if (international){
if (amount * 0.15 >= 50){
return 50.0;
}
else {
return amount * 0.15;
}
}
else{
if (amount > 75){
return amount * 0;
}
else {
return amount * 0.10;
}
}
}
fun main(args: Array<String>) {
val total = readLine()!!.toDouble()
val international = readLine()!!.toBoolean()
println(shippingCost(total, international))
}
+ 3
Simba is right. Here is just an additionel tip: You can also use an if-statement inside a return. Like this:
https://code.sololearn.com/c6f3aa6fQAIX/?ref=app
+ 2
Here is what I tried
fun shippingCost(amount: Double, international: Boolean): Double {
if (amount < 75 && !international){
return total = amount + (total * 0.1);
}else if (amount > 75 && !international){
return total += amount ;
}
if (international ){
var maxfee = 50;
var fee = amount * 0.15;
while (fee <= maxfee){
total = amount + fee;
}else {
total = 50 + amount;
}
}
}
fun main(args: Array<String>) {
val total = readLine()!!.toDouble()
val international = readLine()!!.toBoolean()
println(shippingCost(total, international))
}
+ 2
Simba Coding Cat [mouse break] thanks so much now it works