Skillcrush students are given a chance to practice translating a flowchart into pseudocode with a challenge exercise. Skillcrush provides students with a sample flowchart that they need to practice. The only hint students are given in this challenge is to use military time along with the greater than and less than symbols.
Solution
First, we are going to define the variables. If you look at the flowchart, it looks like you will need two variables. One is going to be grandma’s tea and the other is the time.
Grandma’s tea won’t have any value set to it, but the time variable is where the time of the day will be stored. After the variables, we will add the start and stop keywords. Then we can start adding everything we need in between these two keywords.
If-else statements
We are going to need if-else statements for this pseudocode so let’s start with the first if statement. First, we need to see if Grandma has asked for a cup of tea. So this statement will ask if grandma asked for a cup of tea.
If she has, this is where the user will tell us what time of day it is. We can indicate this with input time. There are different results for each time of day so we will need to nest some if-else statements in our pseudocode.
The first if statement is where we will check to see if it is morning. We can do this by saying if time < 12. After that, we will want to set the results that will happen. So we will say the computer needs to make English Breakfast tea with milk and set grandma’s tea variable to this value.
Next, let’s tackle the evening. We will create another if statement that checks if the time is greater than 16. The result of this if statement is to make spearmint tea in her evening cup.
We will set the grandma’s tea variable to the same value. The last thing to tackle is the else statement. This is what will happen if grandma wants tea between 12 p.m. and 4 p.m.
Here is where you will tell the computer to make Jasmine Pearl tea with honey. This is also the value we will set for grandma’s tea. All that is left to do is output grandma’s tea regardless of tea. Just backspace and write output grandma’s tea before the stop keyword.
Finished Pseudocode
We are finally finished with the pseudocode. Here’s a sample version of what it might look like.
STORE Grandma's tea
STORE time AS the time of day it is
START
IF Grandma asks for a cup of tea
INPUT time
IF time < 12
THEN make English Breakfast tea with milk
Grandma's tea = English Breakfast tea with milk.
IF time > 16
THEN make Spearmint tea in her evening teacup.
Grandma'stea = Spearmint tea in her evening teacup
ELSE
Make Jasmine Pearl tea with honey.
Grandma's tea = Jasmine Pearl tea with honey.
OUTPUT grandma's tea.
STOP
Top comments (0)