Introduction to computer programming with flowcharts

October 30, 2020



When I was a student back in the 90's, flowcharts were a widely used tool to teach students the basics of computer programming. A flowchart is a diagram that represents all the necessary steps for solving a specific task.

In my opinion, beginner programmers should give flowcharts a chance as they provide a very simple learning model. And I think that, given the step-by-step nature of the flowchart, and with enough practice, it can give students a great confidence in their own skills.

Moving along..

The following flowchart represents a simple program that asks the user for a number, stores it in a variable called "X", then adds 1 to "X", and finally prints the value of "X".

If you were to run this program and gave it the number 10, the program would output the number 11. If you gave it the number 20, it would output 21, and so on.

But computer programs can be more complex. For instance, the following flowchart represents a program that asks the user for a number, and checks if it is greater than 10. If it is greater than 10, it writes "X is greater than 10", else it writes "X is not greater than 10".

With only these kind of blocks you can do a lot of things! Here's another program that asks the user for a number and writes "Hello World" that many times.

Basically, while X is greater than 0 it prints "Hello World" and subtracts 1. When X reaches 0 the program ends.

I will leave you with a couple of exercises that you can use to practice your flowcharts-fu!

Basic exercises

  1. Do a flowchart that places X=0 and then outputs it (this one's really basic).
  2. Do a flowchart that ask the user for a number, multiplies it by 2 and then output it.
  3. Do a flowchart that asks the user for two numbers (one at a time, you may call them X and Y), stores the sum in a variable Z, and outputs it.
  4. Do a program that asks the user for two numbers (again, one at a time), and swaps the value of the variables (you may need a third temporary variable).
  5. Do a program that asks the user for the number of hours, the price per hour and outputs how much is due.

Exercises with comparisons

  1. Do a program that asks the user for two numbers and checks if they are equal or not. The program should write something like "the numbers are equal" or "the numbers are different".
  2. Do a program that asks the user for two numbers and outputs the value of the larger one.
  3. Do a program that asks the user for two numbers and outputs the value of the smaller one.
  4. Do a program that asks for three numbers and outputs the value of the larger one.
  5. Do a program that asks for three numbers, computes their average, and writes "Cold" if the average is less than 20. If it's greater or equal than 20, it should write "Warm".

Exercises with loops

  1. Do a program that asks for a number X and writes "Hello World" X times (see above!).
  2. Do a program that asks for a number X and sums all integers from X to 1. For instance, if X=4, it should do 4+3+2+1. Hint: keep the sum in another variable, and initialize it as 0.
  3. Do a program that asks for a number X and outputs the factorial of X. For instance, the factorial of 4 is 4x3x2x1.
  4. Build a small program that implements the guess game. The program should ask user 1 for a number X. Then, user 2 must guess the number. The program must keep saying that the number Y (which is the number that user 2 inserts) is greater or smaller than X. The program should end when the numbers are equal.


Have fun!
João Ventura

PS: All flowcharts were made with https://app.diagrams.net/.