View Full Version : I am learning to use flow charts for school. How can I improve this flowchart?
03-20-2012, 04:04 PM
I have been playing with micro-controllers as a hobby for about 3 years now and I have yet to make a flow chart. For my EE101 class I have to make a flow chart to solve a problem."Build a flow chart using counters to add the odd numbers between 1 and “n”. Where “n” is a positive integer inputted." I think I am close however I see two problems. The red box needs some type of function to determine if the number is even or odd. my arrows go every where the examples shown in class seemed to flow smoothly. I would appreciate any help or suggestions. thank you
Do you create flow charts for most of your projects? If so do you make them before or after you write the code?
03-20-2012, 04:15 PM
In some programming languages, ODD is a built-in function. You could have "IF ODD(CNT)" in that decision block. You could also write "IF (CNT & 1) = 1" if the logical and operator (&) is allowed. Another alternative is to write "IF (CNT // 2) = 1" if the modulus or remainder operator (//) is allowed.
I've been programming for many years and I've rarely created a flow chart unless I was required to for a class or work project. I have found it much more useful to create a "pseudo-code" program where the control structures like IF, FOR, REPEAT, etc. are written out in a sort of functional style using indenting and the rest of the program is given as prose descriptions of what's to be accomplished at that point in the program. When I've had to create flow charts, I would make them from the "pseudo-code".
Flow-charts aren't used very often, these days. When I worked for Xerox Research (UK) I designed the user interface for a new copier, and the software engineer insisted on a flow- chart instead of the pseudo-code I wanted to use. It was rather complex and ended up as something like 20 A3 sheets, I covered one wall in our office in them. I was rather surprised when it all worked, without any changes.
03-20-2012, 04:29 PM
Is there a way to use an algebraic function to find out if CNT is even or odd? We have not used micro controllers in that class yet. We will start with the arduino next week, to bad we cant use basic stamp or propeller.
03-20-2012, 04:35 PM
Personally I would much rather look at code than a flow chart. I think the reason we are using them is to learn how to use a series of logical steps to solve a problem.
03-20-2012, 04:36 PM
All of my projects start with a flowchart and a functional diagram (sort of an org chart for the device). I use Microsoft Visio when I don't use paper and pencil. Once I start on the project, I rarely update or finalize the chart unless I am using it as a communication tool when I show the project to others. My Reverse Geocache Project on the forums has a program flow diagram in the project thread. I made it from my scribbles to show others my train of thought for the code (the code is a little messy)
03-20-2012, 04:54 PM
In C or C++ which is used with the Arduino, the modulus operator is written as %. I showed it as // which is used in some other languages. You'd write "IF (CNT % 2) == 1" to test for odd. Look in the Arduino documentation for details.
Beau Schwabe (Parallax)
03-20-2012, 06:24 PM
Perhaps I'm a bit of old school, but I have used a flowchart or pseudo flowchart variant many times to work out complex problems. I will admit, most of the time though when a solution was found, it turns out that the problem wasn't very complex at all. Using a flowchart helped me to sort out what needed to happen, and in some cases simplify any redundancy.
There are a few rules that I was taught with flowcharts by a professor several years ago that have stuck with me.
1) Only one START and one STOP allowed
2) No entrapments ; a flowchart should not cross lines and/or paint itself in a corner allowing for escapement.
3) A functional block should only have one input and one output
4) A decision block should only have one input and two outputs
Following that, rule #1 in your flow chart is broken, but can be easily be fixed by combining the "OUTPUT ANS".
Rule #3 is broken and two of the decision blocks could be combined into one decision block. Since BOTH outputs from the decision blocks are going to the same locations and since the decision that needs to be made is the same at both decision block locations, this redundancy can be reduced.
These rules aren't written in stone by any means, but it does make for a more streamline flow architecture if they are followed.
03-20-2012, 07:39 PM
Is there a way to use an algebraic function to find out if CNT is even or odd?
I typically test bit0 of the value to do this. If bit0 is 1 the value is odd, otherwise even. In Spin:
if (value & %1)
' value is odd
' value is even
Like others I use a mix of flow-charts (usually for processes, not the whole program) and pseudo-code.
BTW... 'CNT' is a known entity in the Propeller (system counter) so you may not want to use this in your flowcharts unless that is the actual intent. In your chart I think you're actually meaning "count." The idea behind flowcharts is clarity -- this is a case where an abbreviation can lead to confusion.
03-20-2012, 07:57 PM
Nitpicking, perhaps, but the expressions you used are in the form
a+b = c
But they are usually coded
03-20-2012, 09:48 PM
What cavelamb said, but its not nitpicking. The idea is to make things clearer, so don't make it worse by writing the assignments backwards.
Also, the Flowchart is done first, to get a good "picture" of how the logic is going to flow.
Pseudocode is done next, after you know how the logic is going to flow, when you want to figure out how the program is going to be arranged.
Experts can appear to skip steps, but they do not; they simply have enough experience and do it in their heads (more or less).
Non-experts do skip steps, and have disasterous results, particularly when they are working in groups. We see this at "professional" organizations that chronicaly miss schedules and deadlines, and have never-ending bug lists.
The rule of thumb is it takes longer to skip steps than it takes to simply take the time and do it "right". Don't skip the flow chart unless you have already deomonstrated you are an expert, by having a (previous) project that showed you no longer need them.
03-20-2012, 11:56 PM
I've never understood flowcharts. I prefer circuit diagrams http://www.explainxkcd.com/2010/04/21/circuit-diagram/
03-21-2012, 12:04 AM
Mostly when working in assembler and I feel I'm juggling too much in my head I just get pencil and paper and lay it all out. Years ago I used the Z8 a LOT and I loved coding that more than any other but when modifying old code and there is an up to date flow chart available it was SO EASY to pick up. No matter how well you comment your code sometimes..... why did I do this??? read the comment and .. yea so?? but looking at a flow chart is like standing back and looking at a picture and it very quickly makes sense.
Odd and even?? well in binary integer if the lsbit is set its odd - to test you have to use whatever your language allows; I guess anding with one is quickest...
While I'm at it, I do miss the old dot matrix fanfold continuous paper - Ive printed out assembler maybe 25 - 30ft long. Unfold a big chunk on the floor - hands and knees - ah those were the days
03-21-2012, 12:41 AM
To actually answer the question (ahem)
( I cant quite figure your flowchart soooo....)
n>0? YES> ------>count=count+1------>-is count odd? YES>---->answer = answer+count------>count=n? YES---->--Print "sum off odd number from 1 to ";n;" is ";answer-------END
NO | NO NO
| | | |
Ever so sorry but what I typed in the box DID NOT appear as I typed it - its seems that multiple spaces to align stuff is not allowed and not having flowchart software
Gosh I think thats it but its a lot easier with pen and paper (It looks ORRIBLE done like this!!!)
03-21-2012, 02:10 AM
@tritonium, try putting the [ code ] and [ /code ] tags around your box and it should all line up
03-21-2012, 02:58 AM
Big +1 on the Z8.
They still make 'em too.
03-22-2012, 06:15 AM
I reconstructed my flowchart using some of the ideas posted. I also changed the logic of the flow chart.
For this assignment I was not allowed to use code. I was only allowed to us algebraic functions.
Any suggestions are appreciated. thanks!
P.S. I agree that c=a+b looks better and is more logical than a+b=c. The examples given in class were in a+b=c format and my teach is picky about having things his way.
03-22-2012, 06:44 AM
Just to be clear. In mathematics expressions like:
a + c = d
d = a + c
Are statements of fact. i.e. that the stuff on the left side of the "=" is the same value as the stuff on the right hand side.
When used as an assignment statement in computer programming they have a different meaning. So
d = a + c
means "add a and c and make d equal to the resulting value.
This is why languages often have different types of equals operators. In C for example "=" means assignment whereas "==" means compare for equality, as used in "if" statements.
In most languages things like " a + c = d" have no meaning as assignments and are an error.
As for flow charts, I have not seen any one using them for decades, professionally or otherwise. In the mid 1970's we were taught flowcharting whilst learning to program in BASIC. Given that BASIC is a crude and unstructured language flow charts helped a bit.
For my first real work, programming in assembler we used to write out what we wanted to do in pseudo code, in our case something that looked like Algol. Then proceeded to write that in assembler language. Then hand assembled that into hex for the loader. We had no assembler for that processor at the time.
In that position pseudo code was essential to keep you ideas straight and the code in a good structure. I discovered that pseudo code was a lot better way to do this than flowcharts.
P.S. I take back my statement about not seeing flow charts for decades. Just remembered that last year I had to implement a serial line protocol that was specified with flow charts. One for the master end and one for the slave. The protocol was not complicated but those flow charts did not help to understand it and turned out to be wrong anyway! Besides in that case the flow charts indicate protocol behavior and not code flow. State transition diagrams would have been better.