Skip to main content
Engineering LibreTexts

3.4: Psuedocode

  • Page ID
    29025
  • Overview

    Pseudocode is one method of designing or planning a program. It is used by a lot of instructors to teach software design. In all my years as a software developer I never used pseudocode and therefore do not teach it. It is covered briefly here in case you run into this concept at some point in your coding career. 

    Pseudo means false, thus pseudocode means false code. A better translation would be the word fake or imitation. Pseudocode is fake (not the real thing). It looks like (imitates) real code but it is NOT real code. It uses English statements to describe what a program is to accomplish. It is fake because no compiler exists that will translate the pseudocode to any machine language. Pseudocode is used for documenting the program or module design (also known as the algorithm).

    The following outline of a simple program illustrates pseudocode. We want to be able to enter the ages of two people and have the computer calculate their average age and display the answer.

    Input
      display a message asking the user to enter the first age
      get the first age from the keyboard
      display a message asking the user to enter the second age
      get the second age from the keyboard
    Processing
      calculate the answer by adding the two ages together and dividing by two
    Output
      display the answer on the screen
      pause so the user can see the answer
    

    After developing the program design, we use the pseudocode to write code in a language (like Pascal, COBOL, FORTRAN, "C", " C++", etc.) where you must follow the rules of the language (syntax) in order to code the logic or algorithm presented in the pseudocode. Pseudocode usually does not include other items produced during programming design such as identifier lists for variables or test data.

    As I have stated, I do not spend much time on pseudocode, instead I like the idea of simply creating your comments, and then come back and actually write your code. For simple programs this looks overly simple, but for more complex code involving functions it is helps a lot to track the flow of your code.

    // Preprocessor directives
    
    int main()
      // Ask the user for the first age
      // Accept input into integer variable age1
      
      // Ask the user for the second age
      // Accept input into integer variable age2
    
      // Calculate average, and assign to integer variable: myAnswer = (age1 + age2) / 2
    
      // Output the results

    Definitions

    Adapted from: "Pseudocode" by Kenneth Leroy Busbee is licensed under CC BY 4.0 (Download for free at http://cnx.org/contents/303800f3-07f...93e8948c5@22.2)

     
    pseudo
    Means false and includes the concepts of fake or imitation.