โปรแกรมการหาส่วนลดจากการซื้อสินค้าจำนวน 2 ชิ้น
โดยกำหนดให้เมื่อซื้อสินค้าราคารวม 0- 1,000 บาท ลดราคาร้อยละ 10
หากซื้อสินค้าราคารวม 1,001-5,000 ลดราคาร้อยละ 15 หากซื้อสินค้าราคามากกว่า 5,000 บาทขึ้นไปลดราคาร้อยละ 20
ผังงาน
psudo code
start
set price1=0.00,price2=0.00,total=0.00,discount=0.00
input price1
input price2
compute total=price1+price2
if total>=0 and total<=1000 then
discount=total*10/100
else if total>=1001 and total<=5000 then
discount=total*15/100
else if total>5000 then
discount=total*20/100
endif
print discount
stop
ตัวอย่างการโปรแกรม
price1=0.00
price2=0.00
total=0.00
discount=0.00
price1=float(input("input price1:"))
price2=float(input("input price2:"))
total=price1+price2
if total>=0 and total<=1000:
discount=float(total*10/100)
elif total>=1001 and total<=5000:
discount=float(total*15/100)
elif total>5000:
discount=float(total*20/100)
print (discount)