Answer:
string state
num pounds
num SIZE = 5
string STATES[SIZE] = [“IL”, “IN”, “OH”, “MI”, “WI”]
num PRICES[SIZE] = [0.60, 0.55, 0.70, 0.65, 0.67]
num temp
string foundIt
string BAD_STATE_MSG = "Sorry, we do not ship to ”
string FINISH = “XXX”
getReady()
while state <> FINISH
findPrice()
endwhile
finishUp()
stop
getReady()
output "Enter state or ", FINISH, " to quit"
input state
return
findPrice()
foundIt = "N"
temp = 0
index = 0
while temp < SIZE
if state = STATES[temp] then
foundIt = "Y"
index = temp
temp = SIZE
endif
temp = temp + 1
endwhile
if foundIt = "N" then
output BAD_STATE_MSG, state
else
price = PRICES[index]
output “Enter pounds “
input pounds
output “Cost per pound to ship to ”, state, “ is ”, price
output “Total cost is ”, price * pounds
endif
output "Enter next state or ", FINISH, " to quit"
input state
return
finishUp()
output "End of job"
return
Explanation:
- Initialize the required variables and arrays.
- Inside the while loop, call the findPrice() method.
- Run a while loop until temp is less than Size.
- If state is found then set the value of foundIt variable to "Y" and assign the value of temp to index variable.
- Finally call the finishUp method and return.