Lompat ke konten

Lesson 64: Flowchart to sketch

English

From flowchart to code

  • In the exam you trace flowcharts. Here you turn one into a sketch and run it.
  • Each shape becomes a piece of code:
Shape Code
rectangle (process) total = total + groupSize;
parallelogram (input) read a value from the Serial Monitor
diamond (decision) if (...) { ... } else { ... }
arrow back up the next time round loop()

Exam flowchart: set NumberGroups and Total to 0; input GroupSize; if GroupSize is 0, Average is Total DIV NumberGroups, output it and stop; if not, add 1 to NumberGroups, add GroupSize to Total and input again

  • finished is the STOP box: once it is true, loop() does nothing more.

Masuk atau buat akun

IGCSE, A-Level & AP