Help Please: I need some help and guidance to solving this problem

Week 4 CheckPoint – Repetition and Decision Control Structures

In one of the week 3 discussion questions we discussed the algorithm that would be required to make a peanut butter sandwich. In this CheckPoint you will need to take that one step further and create a program design to make a peanut butter sandwiches. Below you will find a partial program design; you need to complete it by adding the pseudocode in the required areas. You need to add one repetition (loop) control structure and one decision control to complete the program design. The user will decide how many sandwiches are made; this is where the loop will be used. The user will decide if the sandwich includes jelly, and, if it does, what flavor of jelly; to keep it simple we are only allowing grape or strawberry jelly.

Analysis

Process:
1. Ask user how many sandwiches to make
2. Ask user if they want jelly on their sandwich
3. If jelly is requested, ask user what flavor (grape or strawberry) of jelly they would like
4. Make peanut butter and, if required, jelly sandwiches

Input:
NumberOfSandwiches (integer)
IncludeJelly (string; values Yes/No)
TypeOfJelly (string; values Grape/Strawberry)

Output:
Sandwich

Design

Main Module

Declare NumberOfSandwiches as integer
Declare IncludeJelly as string
Declare TypeOfJelly as string
Declare Continue as Boolean
Set Continue to true

Do While Continue = true
Call InputModule
EndDo

End Main Module

InputModule

Display "How many sandwiches would you like to make? Enter 0 to end program."
Input NumberOfSandwiches

If NumberOfSandwiches = 0
Set Continue = false
Else
Display "Do you want jelly on your sandwiches?"
Input IncludeJelly

If IncludeJelly = “Yes”
Display “What type of jelly; Grape or Strawberry?”
Input TypeOfJelly
EndIf

**** Students – add a loop here to create the number of sandwiches requested by the user – within the loop you need to invoke (call) the SandwichModule to create the sandwiches. Do not over think this one; the loop should loop over the NumberOfSandwiches and reduce the value each time a sandwich is made until NumberOfSanwiches is equal to zero.

Make sure you review the given code in this assignment, you do not want to repeat steps that are already done.

EndIf

End InputModule

SandwichModule

Get bread
Spread peanut butter on bread

**** Students – add decision control structure here to add jelly to the sandwich if the user requested it. Hint: you will want to use a nested decision control structure.

End SandwichModule

To solve this problem and complete the program design, you need to add a loop control structure and a decision control structure.

Let's start with the loop control structure. In the given design, you can see a placeholder for the loop. It says, "**** Students – add a loop here to create the number of sandwiches requested by the user."

To implement this loop, you can use a for loop or a while loop. Since you already have the NumberOfSandwiches variable, which stores the user's input for the number of sandwiches, a for loop would be suitable in this case. Here's how the loop can be added:

```
For i = 1 to NumberOfSandwiches
Call SandwichModule
Next i
```

This loop will iterate from 1 to the value of NumberOfSandwiches, calling the SandwichModule repeatedly to create the sandwiches.

Next, let's move on to the decision control structure. Again, in the given design, there is a placeholder for the decision control structure. It says, "**** Students – add decision control structure here to add jelly to the sandwich if the user requested it."

To implement this decision control structure, you need to check if the user wants jelly on the sandwich and then, based on their choice, add the appropriate flavor of jelly. Here's how the decision control structure can be added:

```
If IncludeJelly = "Yes" Then
If TypeOfJelly = "Grape" Then
Add grape jelly to the sandwich
Else If TypeOfJelly = "Strawberry" Then
Add strawberry jelly to the sandwich
End If
End If
```

Inside the SandwichModule, above the line "End SandwichModule," add the above decision control structure. This will check if jelly is requested by the user and, if so, add the specified flavor of jelly to the sandwich.

With these additions, your program design should be complete, incorporating both a loop control structure and a decision control structure.