Introduction to Fortran

Simple Program Construction with Pseudocode » Making Decisions

So far our pseudocode looks something like this:

  1. Use app to gather forecast low and high temperature, cloud cover,
and precipitation for today. 2. Use calendar to find whether it is a workday or weekend.

For the rest of this program, we will focus only on the high temperature as our weather variable. Let’s try to figure out what the pseudocode would look like for the decision-making process based on temperature. Let’s assume that your temperature threshold is a forecast high temperature at or above 70°F for lighter tops.

Question 1 of 5

Which two of the following pseudocode snippets would best represent the 70°F threshold for top selection? Select the best two pseudocode snippets.

The correct answers are a, d.

These two pseudocode snippets together with the forecast high temperature data would help you make the proper selection of tops. You may also be able to substitute the word “when” for “if” and the pseudocode would still make sense. Using “if” is preferable for reasons you will see later when we get to actually coding this example up. Notice that choices c and d are very similar - but only choice d is correct, given that you've already accounted for temperatures greater than AND equal to 70 as part of your threshold.

Please make a selection.

Question 3 of 5

Write a pseudocode snippet that makes the decision to wear pants (below 61°F) or shorts (above 60°F)?


Your pseudocode should look a lot like the following:

  If the forecast temperature is above 60°F, select shorts,
else select pants.

You could have chosen to express this slightly differently by switching the order of the shorts and pants and thus the decision-making point. That would look like this:

  If the forecast temperature is at or below 60°F, select pants,
else select shorts.

Question 4 of 5

Does the order of top and bottom decisions make a difference in your program?

  If the temperature is at or above 70°F, select a short-sleeved top,
else select a long-sleeved top. If the forecast temperature is above 60°F, select shorts,
else select pants.

The correct answer is b.

These two pieces of clothing are separate from each other, so the order doesn’t make a difference. Ok, ok, it makes a difference if you want the second piece of clothing to match the first piece, but we digress... so for now, no it doesn’t matter what order they go in.

Please make a selection.

Challenge Question

Write 1 pseudocode decision snippet based on the other weather information.


Some options include:

Based on precipitation probability, you might need to take an umbrella or raincoat.

  If the forecast chance of precipitation is greater than 50%,
take an umbrella or a raincoat.

Based on cloud cover percentage, you might need sunglasses.

  If the forecast cloud cover is less than or equal to 70%,
take sunglasses.

Based on the if the low temperature will be below a certain value and the high temperature will be above a certain value, you might want to layer your clothing.

  If the forecast low is less than 50°F AND the forecast high is
greater than or equal to 70°F, wear layered short-sleeved top under a long-sleeved top.

There are numerous more options for pseudocode you could write based on the weather information gathered from the app. What if the temperatures are really low? Maybe checking the windchill becomes important, or maybe you need to wear gloves and a hat below a certain temperature. The list goes on and on.

We have other information that we can take advantage of too that will help us make the clothing decisions. We know whether it is a workday or a weekend. Most individuals will dress differently at work than on the weekend. Because of this we could add another decision point in our pseudocode to help us make a decision based on whether it is a workday or weekend.

Question 5 of 5

Based on the previous pseudocode, where would the new decision making point occur? Drag the new pseudocode snippet (first in the list) to the correct location.

  1. If today is a weekend… else ...
  2. Use app to gather forecast high temperature for today.
  3. Use calendar to find whether it is a workday or weekend.
  4. If the forecast temperature is at or above 70°F, select a short-sleeved top,
    else select a long-sleeved top.
  5. If the forecast temperature is above 60°F, select shorts,
    else select pants.