How does Instruction 2 affect the updates in a flow chart for coding?

  • Context: Comp Sci 
  • Thread starter Thread starter member 428835
  • Start date Start date
  • Tags Tags
    Charts Code Flow
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
7 replies · 2K views
member 428835
Homework Statement
See the attached screenshot.
Relevant Equations
nothing comes to mind
I found this as problem 3/42 from here (copied below for viewing convenience). I'm a little confused about Instruction 2. The way I interpret it, upon the first loop, no evaluation is occurring, but instruction 1 now becomes "increase Box 2 by 2". So now the three instructions are
1) increase the last value mentioned in box 2 by 2
2) change instruction 1: Increase the last box number mentioned in it by 2.
3) Is the last box number mentioned in Instruction 1 equal to (number in box 3)?

But this makes me think box 2 will becomes 2 -> 4 ->6... since it is the ONLY, and therefor last, box mentioned. What am I missing?
flow_chart.png
 
Physics news on Phys.org
joshmccraney said:
The way I interpret it, upon the first loop, no evaluation is occurring, but instruction 1 now becomes "increase Box 2 by 2".
I think that the exercise seeks to have you carefully track the operation and result of each instruction.

What number is in box 2 after after instruction 1 is executed?
What is the last number in instruction 1?
Isn't changing that number the only modification that instruction 2 makes to instruction 1?
 
Last edited:
sysprog said:
I think that the exercise seeks to have you carefully track the operation and result of each instruction.

What number is in box 2 after after instruction 1 is executed?
What is the last number in instruction 1?
Isn't changing that number the only modification that instruction 2 makes to instruction 1?
I'll answer your questions as you've asked:
1) 0
2) 2
3) I think not. Doesn't instruction 2 literally change instruction 1, so that we only evaluate the subtraction on the first iteration, and after that we just add 2, since the instruction has changed?
 
3) I think not. Doesn't instruction 2 literally change instruction 1, so that we only evaluate the subtraction on the first iteration, and after that we just add 2, since the instruction has changed?
In this instance "change" doesn't mean 'exchange' or 'replace'; it means modify ##-## instruction 2 says modify instruction 1 so that the last box number in instruction 1 is increased by 2 ##-## the last box number in instruction 1 is the number of the box at which the result of the subtraction is to be stored.
 
Last edited:
  • Like
Likes   Reactions: pbuk
On the first pass through the loop, what is the last box number mentioned in instruction 1? What does instruction 1 say after we increase it by 2?
 
  • Like
Likes   Reactions: sysprog
Oh, note that none of the answers A-D is correct. There are hundreds of these "interview questions" sites, all of them I have seen are useless.
 
pbuk said:
Oh, note that none of the answers A-D is correct.
The question on the site has answers A-E.

1650277490840.png
 
  • Haha
Likes   Reactions: pbuk
sysprog said:
The question on the site has answers A-E.
Oh, sorry for giving the game away!
 
  • Haha
Likes   Reactions: sysprog