主题:我的java哪个部分错了?
var item
var tax
var totalcost
//input
item = inputString ("Enter the letter corresponding to the item you are interested in")
tax = inputNum ("Enter provincial sales tax rate (in $)", 0.08,2)
//processing
if (item=="a")
{
outputLine ("Item (a):")
outputLine ("T-Shirt: Grey")
totalcost= (1+tax)*10
output ("Cost with tax: $"+totalcost)
}
if (item=="b")
{
outputLine ("Item (b):")
outputLine ("Sweater: White")
totalcost= (1+tax)*12
outputLine ("Cost with tax: $"+totalcost)
}
if (item=="c")
{
outputLine ("Item (c):")
outputLine ("Jean: Blue")
totalcost= (1+tax)*20
outputLine ("Cost with tax: $"+totalcost)
}
if (item=="d")
{
outputLine ("Item (d):")
outputLine ("Boot: Black")
totalcost= (1+tax)*23
outputLine ("Cost with tax: $"+totalcost)
}
else
{
outputLine ("there is no such item")
}
</script>
可以帮我改改如何可以让totalcost最多只可以有2位小数点?
还有最后的else part为什麽也有错,每次得出的答案就算属於a的else那个部分还是会出现
var tax
var totalcost
//input
item = inputString ("Enter the letter corresponding to the item you are interested in")
tax = inputNum ("Enter provincial sales tax rate (in $)", 0.08,2)
//processing
if (item=="a")
{
outputLine ("Item (a):")
outputLine ("T-Shirt: Grey")
totalcost= (1+tax)*10
output ("Cost with tax: $"+totalcost)
}
if (item=="b")
{
outputLine ("Item (b):")
outputLine ("Sweater: White")
totalcost= (1+tax)*12
outputLine ("Cost with tax: $"+totalcost)
}
if (item=="c")
{
outputLine ("Item (c):")
outputLine ("Jean: Blue")
totalcost= (1+tax)*20
outputLine ("Cost with tax: $"+totalcost)
}
if (item=="d")
{
outputLine ("Item (d):")
outputLine ("Boot: Black")
totalcost= (1+tax)*23
outputLine ("Cost with tax: $"+totalcost)
}
else
{
outputLine ("there is no such item")
}
</script>
可以帮我改改如何可以让totalcost最多只可以有2位小数点?
还有最后的else part为什麽也有错,每次得出的答案就算属於a的else那个部分还是会出现