Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Computer Science flowchart help?

  1. Oct 4, 2014 #1
    I have a sample exam in which the teacher provided the answers for, but I am not understanding these flowcharts. I understand actual parameters and formal parameters, but not how I would get the output. Can someone help explain this to me? I have uploaded one of the questions with the answers.

    Attached Files:

  2. jcsd
  3. Oct 5, 2014 #2


    Staff: Mentor

    We'll start at start, the first few stmts initialize variables, the next calls the wat() function.

    So shift over to the second flowchart. Pay attention to the by value and by reference modifiers. By reference means the variable will be changed in the calling program so you need to remember that when you finish with the wat() function. The output stmt prints the answers which the teacher wants to see.
  4. Oct 5, 2014 #3
    Thank you. I understand a little better now. I am just confused as to how we get -6 for k in the main and 8 for s and -8 for p in the method?
  5. Oct 5, 2014 #4


    User Avatar
    Science Advisor
    Gold Member
    2017 Award

    One example. In main, K is set to -2. It is passed by reference to B in WAT, so any change of B in WAT actually changes K. B is changed to B-S=(-2)-4 = -6. That is the final output.
  6. Oct 5, 2014 #5
    Thank you. I understand now:)
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook