It is time to turn to the pseudocode for your LOL Cat clock. Your job is to turn your flowchart into pseudocode. Skillcrush provides students with one hint.
There will be three variables for noon, evening, and time of day. Now that you know the variables, we are going to start putting together all the pseudocode. Put the start and stop keywords first. Then we are going to put all the pseudocode in between.
Solution
First, we need to get the time of day. So after the start keyword, you will need to input the time of day and store it to use later in our algorithm. So we will use the input keyword to input time.
Then we will take the time and put it in a time variable. You will indicate this using the store keyword. Now we can create the variables for noon and evening.
In this example, these variables are stored in military time. So the noon variable is stored as 12 while the evening variable is stored as 18.
START
INPUT TIME
STORE time AS what time it is
STORE noon AS 12
STORE evening as 18
If-else statements
Now that we have our variables, we need to work on our if-else statements. In the first if statement, we want to check if it is morning. We will do this by checking to see if the time is less than noon.
IF time IS LESS THAN noon THEN
OUTPUT “Good morning!”
If this is true, we will output “Good morning!” to the screen. What if isn’t morning? If this if statement is false, we need to check if it is evening next.
We can do this by writing an else if statement to see if the time of day is greater than the evening value. We can do this by asking if the time value is greater than evening. If that is true, it will output “Good evening!” to the user.
ELSE IF time IS GREATER THAN evening THEN
OUTPUT “Good evening!”
Now we need to check to see if it is the afternoon. This will be the else statement in our algorithm. Here is where you will write the output “Good afternoon!” to the user.
ELSE
OUTPUT “Good afternoon!”
STOP
Finished Pseudocode
That’s a wrap on your LOL Cat pseudocode. You now have all the pseudocode you will need to build the LOL Cat clock project. Here’s the completed version of the LOL Cat clock pseudocode with everything put together.
START
INPUT time
STORE time AS what time it is
STORE noon as 12
STORE evening as 18
IF time is LESS THAN noon THEN
OUTPUT "Good morning!"
ELSE IF time is GREATER THAN evening THEN
OUTPUT "Good evening!"
ELSE
OUTPUT "Good afternoon!"
STOP