Shop OBEX P1 Docs P2 Docs Learn Events
I am learning to use flow charts for school. How can I improve this flowchart? — Parallax Forums

I am learning to use flow charts for school. How can I improve this flowchart?

Tony_tsiTony_tsi Posts: 98
edited 2012-03-21 23:44 in Propeller 1
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

EE101_AMF_HW_3-19_flow chart.pdf

Do you create flow charts for most of your projects? If so do you make them before or after you write the code?

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2012-03-20 09:15
    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".
  • LeonLeon Posts: 7,620
    edited 2012-03-20 09:24
    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.
  • Tony_tsiTony_tsi Posts: 98
    edited 2012-03-20 09:29
    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.
  • Tony_tsiTony_tsi Posts: 98
    edited 2012-03-20 09:35
    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.
  • WBA ConsultingWBA Consulting Posts: 2,936
    edited 2012-03-20 09:36
    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)
  • Mike GreenMike Green Posts: 23,101
    edited 2012-03-20 09:54
    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 SchwabeBeau Schwabe Posts: 6,569
    edited 2012-03-20 11:24
    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.
  • JonnyMacJonnyMac Posts: 9,236
    edited 2012-03-20 12:39
    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
      else
        ' 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.
  • cavelambcavelamb Posts: 720
    edited 2012-03-20 12:57
    Nitpicking, perhaps, but the expressions you used are in the form
    a+b = c

    But they are usually coded
    c= a+b
  • prof_brainoprof_braino Posts: 4,313
    edited 2012-03-20 14:48
    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.
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2012-03-20 16:56
    I've never understood flowcharts. I prefer circuit diagrams http://www.explainxkcd.com/2010/04/21/circuit-diagram/
  • tritoniumtritonium Posts: 543
    edited 2012-03-20 17:04
    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

    Dave
  • tritoniumtritonium Posts: 543
    edited 2012-03-20 17:41
    To actually answer the question (ahem)
    ( I cant quite figure your flowchart soooo....)

    answer=0
    count=0
    input n

    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
    | | | |
    |
    <
    <
    <
    <
    ERROR!

    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!!!)

    Dave
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2012-03-20 19:10
    @tritonium, try putting the [ code ] and [ /code ] tags around your box and it should all line up
  • cavelambcavelamb Posts: 720
    edited 2012-03-20 19:58
    Big +1 on the Z8.
    Sweet machine!

    They still make 'em too.
  • Tony_tsiTony_tsi Posts: 98
    edited 2012-03-21 23:15
    I reconstructed my flowchart using some of the ideas posted. I also changed the logic of the flow chart.
    EE101_AMF_new flow chart.pdf
    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.
  • Heater.Heater. Posts: 21,230
    edited 2012-03-21 23:44
    Just to be clear. In mathematics expressions like:

    a + c = d

    or

    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.
Sign In or Register to comment.