历届象屿集团董事长:用C语言的if-else做这题

来源:百度文库 编辑:查人人中国名人网 时间:2024/04/25 14:14:40
根据购买商品的类别和价格,计算打折后商品的实际价格。
如果A类商品,价格在500以下,折扣率为5%。价格在500到1000之间,折扣率为10%,1000以上为20%。

若为B类商品,价格在1000以下为无折扣,1000到2000之间为10%,2000以上为20,其他商品为无折扣

if (a.type=="a")
{
if (a.price<=500)
{
折扣率为5%
}elseif(a.price>500 && a.price<=1000)
{
折扣率为10%
}else
{
1000以上为20%
}
}elseif(a.type=="b")
{
if (a.price<1000)
{
无折扣
}
elseif(a.price>1000 && a.price<2000)
{
1000到2000之间为10%
}
else
{
2000以上为20
}
}

就是将switch语句拆分为if~~~else~~~的语句啊
楼主以后自己多想想就行了啊

dreamliar - 助理 二级

太麻烦了!
没时间了!

不想说了!