1. Flowgorithm Online
  2. Flowgorithm &
  1. Flowgorithm is a free beginner's programming language that is based on simple graphical flowcharts. Typically, when a student first learns to program, they often use one of the text-based programming languages.
  2. Decisions (if statements) Making a decision based on a single value (if statements) When the computer needs to “decide” which branch of a flowchart (or algorithm to follow) it evaluates a variable against some condition that we place on it.
  3. NOTE: Flowgorithm does not allow you to use multiple lines in an Output display, so you have to do each line with a separate Output symbol. Ask the user to input a menu choice. If the user enters 1, 2, 3 or 4, display the appropriate greeting.

Flowgorithm Online

Flowgorithm

Scriviamo un algoritmo che, dato in ingresso un numero num, restituisca il numero di divisori pari di num.

Download

Vectors & 2D matrices in the Flowgorithm DOWLOAD Only one dimensional arrays are supported in the Flowgorithm and limited to the integer, real (floats), boolean and string types. However, two dimensional arrays are natively required in many algorithms.

L’algoritmo è molto semplice:

  • Dichiariamo le variabili intere num, i e cont.
  • Chiediamo e otteniamo in ingresso un valore da memorizzare nella variabile intera num.
  • Inizializziamo la variabile cont a 0 (visto che si aggiornerà facendo riferimento al proprio precedente valore). Tale variabile conterrà il numero di divisori pari di num.
  • Inseriamo un ciclo for (Per) per far scorrere il contatore i da 1 a num.
  • Inseriamo un blocco di controllo (selezione) per verificare se il generico valore i è un divisore di num e se è pari; per far sì che tali condizioni siano verificate contemporaneamente, usiamo l’operatore AND (&&).
  • Ogni volta che i soddisfa le condizioni appena scritte, aumentiamo di 1 il valore di cont.
  • L’algoritmo termina restituendo il valore di cont.
  • Nella finestra che segue mostriamo l’esecuzione per num uguale a 10. I divisori di 10 sono 4 (1, 2, 5, 10) ma solo due due di essi (2, 10) sono pari.

Making a decision based on a single value (if statements)

When the computer needs to “decide” which branch of a flowchart (or algorithm to follow) it evaluates a variable against some condition that we place on it. These decisions are frequently documented in a condition/action table.For instance for the decision below: if age >= 18 we could document it like this:

Flowgorithm book
pathconditionAction
User is 18 or olderage >= 18Print “Go vote!”
User is less than 18age < 18Print “Sorry, not yet”

The diamond shape is used to designate a decision. The “if” is not listed, just the condition.

  • Declare a variable for age
  • Output the instruction to the user and store the result in age
  • Add an IF shape, then double-click the shape to add the condition
  • Back on the flowchart, click on each branch of the if statement and add an action that the program will take (i.e. the message that is output to the user)

Making a decision based on multiple values (if statements with Boolean operators)

In the case of multiple conditions that need to be met, we would use Boolean operators to chain two or more conditions together. Boolean operators:

  • AND – all conditions must be true in order to execute the code
  • OR – only one of the conditions must be true in order to execute the code
  • ! - NOT means that the code will only execute if the condition is not true

For instance for the decision below: if age >= 18 AND enrolled = true we could document it like this:

pathconditionAction
User is 18 or olderage > = 18 AND enrolled = truePrint “Go vote!”
User is less than 18 or not enrolledage < 18 OR enrolled = falsePrint “Sorry, not yet”

Making decisions using multiple values with != (if statements checking for a negative condition)

Many times we need to force the user to enter a certain value that we are looking for. This is especially true when we need to validate the users input before continuing on with the program.

The != operator (not equal) is very useful for this task.The flowchart below asks the user to enter a specific character from the menu. If the condition is met (the user didn’t enter an A, B or C) the true path is chosen. If the condition is not met (user entered an A, B or C) the false path is taken.

Flowgorithm &

Note: We use AND rather than OR here because all conditions need to evaluate to true. For example, they didn’t enter any of the valid inputs (A, B and C).

Nested If (a condition within a condition)

At times we may need to test for a certain condition, and then run a further test on another condition. However, if we want the program to be able to keep track of these individual evaluations we will need a nested conditional statement.

Think of this as an if statement inside another if statement.

In a previous section we were evaluating if a person was old enough to vote AND was enrolled to vote. The condition action table looked like the following:

pathconditionAction
User is 18 or olderage > = 18 AND enrolled = truePrint “Go vote!”
User is less than 18 or not enrolledage < 18 OR enrolled = falsePrint “Sorry, not yet”
Flowgorithm

In this case we can only respond to the two conditions:

Flowgorithm functions
  • Either the user is old enough to vote and is enrolled
  • Resulting in message: “Go vote”
  • Or one of the conditions is false
  • Resulting in the message: “Sorry, not yet”

If we want to be able target each individual condition, we will need a nested structure.

PathConditionAction
User is 18 or older and enrolledage >= 18 AND enrolled = truePrint “Go vote!”
User is 18 or older and is not enrolledage >= 18 AND enrolled = false Print“You are old enough to vote, but are not enrolled.”
User is not 18 or older and is enrolledage < 18 AND enrolled = truePrint “You are not yet 18 and are enrolled”
User is not 18 or older and is not enrolledage < 18 18 AND enrolled = falsePrint “You are not yet 18 and are not enrolled”