Shell脚本基础循环、判断语句练习实例
商场购物车案例
#! /bin/bash
xie=200
ku=150
yi=100
huan=50
chi=120
num=0
for ((i=1;i<=5;i++))
do
echo 是否进入第"$i"家店?
read -p "输入(yes & no)" shu
while [ $shu = "yes" ]
do
echo 1.鞋子 ¥"$xie"
echo 2.裤子 ¥"$ku"
echo 3.衣服 ¥"$yi"
echo 4.手环 ¥"$huan"
echo 5.小吃 ¥"$chi"
echo "您想购买哪件商品?"
read bh
echo "是否继续购物?(yes & no)"
read shu
case $bh in
1)
let num+=$xie
echo 总价为"$num" &> /dev/null
;;
2)
let num+=$ku
echo 总价为"$num"&> /dev/null
;;
3)
let num+=$yi
echo 总价为"$num"&> /dev/null
;;
4)
let num+=$huan
echo 总价为"$num"&> /dev/null
;;
5)
let num+=$chi
echo 总价为"$num"&> /dev/null
;;
*)
echo "您的选择有误,请检查输入"
esac
done
done
echo 您本次购买的总价为:$num
原文地址:https://blog.51cto.com/14484404/2441330
时间: 2024-11-05 13:28:41