Programming


Program Design:  Pseudocode

 

Basic statements

StatementDescriptionVerbiageExample
DeclarationTells computer to set aside space to store dataDeclaration, set, initint num1
OutputDisplays information to the output device such as screen or printerdisplay, output, print, sayOutput “Enter a number. “
InputStores data into a declared variable in the computer’s memoryinput, scan, store, enterInput num1
Assignment statementStores values or results of calculations into a declared variableassign, computesum=num1+num2
Decisional (Selection)

statement

Checks a condition, if the condition is met (true) commands are executed, else (false) other commands are executedifif(num1<10)
Iteration (Loop) StatementRepetitively completes commands while a condition is truewhile, for, do..whilefor(count=1; count<=4; count++)

 

Pseudocode Example

Set int value

Display “Enter a Number: “

Store value

If value > 10

Output “Your number is greater than 10”

What is happening with the pseudocode above?

  • Set – tells the computer to set aside some space in the computer’s memory naming the variable value and telling the computer to look for integer data to be stored.
  • Display – prompts the user to enter a number.
  • Store – stores the number the user keys in from the keyboard into the variable named ‘value.’
  • The Decisional if statement checks to see if the number stored in the variable named value is greater than 10 – if it is (true)
    • a message will be displayed via the output that their number was greater than ten.

 

 

Now, let us try to write our own pseudocode.

Here is the program description:  Represent the logic of a program that allows the user to enter two values. The program outputs the product of the two values.

  1. Open MS Word.
  1. First you should review the program description and decide what variables you might need to declare to store data in the computer’s memory – since we want the user to enter two values, we will at least need to declare two variables. We will use the declarations language (see chart above). Type the commands below into your Word document.

Start

Declarations

Integer num1, num2

The statements above start the program and sets aside space in the computer’s memory with variables named ‘num1’ and num2’ (keep in mind that you can name variables anything you want just as long as you call them the same when using them in the program – also they are case sensitive). We have included the verbiage ‘Integer’ which tells the computer to expect integer data to be entered and stored.

  1. Adding to the statements up above, we now must ask the user to enter the two numbers (be sure to review the description up above). To display information to the computer’s screen we will use an output statement (check chart up above for other names you can use). If we do not prompt the user to enter the values, nothing will appear on the screen, and they will not know what to enter. Notice that the text is contained in double quotations – you will need to use this notation when creating flowcharts and C programs. Here is the next line of pseudocode to add to your Word document.

Output “Enter two numbers: “

 

  1. Now that we have prompted the user with the output statement, we need to store the values the user keys in from the keyboard. We will use input statements to store the values the user types into the declared variables. Add the next two pseudocode statements to your Word document. Refer to the chart above to see the different pseudocode verbiage that can be used.

Input num1

Store num2

  1. The next statement we need to include is an assignment statement that will store the values multiplied together, however, before we do that, we need to declare another variable to store the result of the computation. Add the variable ‘multiply’ to the Declarations statement. Since it will be storing an integer value as well, we can just add a comma and the variable name next to the variable num2. The new pseudocode statement should look like this:

 

Declarations

int num1, num2, multiply

  1. Now it is time to create the assignment statement. Add the following statement under your input statements to your Word document. The values stored in the variables ‘num1’ and ‘num2’ will be multiplied and the result will be stored in the variable named ‘multiply’

multiply = num1*num2

  1. The last thing the program asks is to output the value of the numbers multiplied together. We can do this by adding another output statement. Add the next pseudocode statement to your Word document.

Display “The values multiplied together are:“  multiply

Stop

So, the pseudocode for the program description: Represent the logic of a program that allows the user to enter two values. The program outputs the product of the two values. should look as follows:

Start

Declarations

Integer num1, num2, multiply

Output “Enter two numbers: “

Input num1

Store num2

multiply = num1*num2

Display “The values multiplied together are:“  multiply

Stop

Submission instructions:  Upload the Word document containing the pseudocode up above for grading.