由于有三个商店,您可能希望保留每个单独的工资单金额,即使规格似乎并不在意。这样,您可以使用特殊的商店代码 0 来表示您已完成。
伪代码如下:
store1 = 0
store2 = 0
store3 = 0
print "Enter store, or 0 to end: "
input storenum
while storenum <> 0:
print "Enter a payroll amount: "
input amount
select storenum:
case 1:
store1 += amount
end case
case 2:
store2 += amount
end case
case 3:
store3 += amount
end case
end select
print
print "Enter store # or 0 to end"
input storenum
end while
print
print "Store 1 payroll is ", store1
print "Store 2 payroll is ", store2
print "Store 3 payroll is ", store3
print
print "Total payroll is ", store1 + store2 + store3
这将导致像这样的成绩单:
Enter store, or 0 to end: 3
Enter a payroll amount: 33
Enter store, or 0 to end: 2
Enter a payroll amount: 22
Enter store, or 0 to end: 3
Enter a payroll amount: 11
Enter store, or 0 to end: 0
Store 1 payroll is 0
Store 2 payroll is 22
Store 3 payroll is 44
Total payroll is 66