44.4k views
5 votes
Write structured pseudocode that describes how to buy a new shirt. Include at least two decisions and two loops.

User Phatmann
by
8.1k points

1 Answer

2 votes

Answer:

Here is a structured pseudocode that describes how to buy a new shirt, including at least two decisions and two loops:

```

procedure buy_shirt()

declare

desired_color: string

desired_pattern: string

desired_size: string

desired_price: integer

found_shirt: boolean

begin

print "What color shirt do you want?"

read desired_color

print "What pattern do you want?"

read desired_pattern

print "What size do you want?"

read desired_size

print "What price are you willing to pay?"

read desired_price

found_shirt := false

while not found_shirt do

print "Searching for a shirt..."

for each shirt in store do

if shirt.color = desired_color and shirt.pattern = desired_pattern and shirt.size = desired_size and shirt.price <= desired_price then

found_shirt := true

break

end if

end for

end while

if found_shirt then

print "Found shirt!"

print shirt.color, " ", shirt.pattern, " ", shirt.size, " ", shirt.price

print "Do you want to buy it?"

read answer

if answer = "yes" then

buy shirt

end if

else

print "No shirt found."

end if

end procedure

```

This pseudocode includes two decisions: one to determine whether the desired shirt has been found, and another to determine whether the user wants to buy the shirt. It also includes two loops: one to search the store for the desired shirt, and another to allow the user to enter their answer.

Step-by-step explanation:

User Jeremy Weathers
by
7.8k points