Leah.J
Badges: 13
Rep:
?
#1
Report Thread starter 1 year ago
#1
Name:  Screenshot (6).png
Views: 33
Size:  73.2 KBName:  Screenshot (8).png
Views: 27
Size:  18.7 KBName:  Screenshot (8).png
Views: 27
Size:  18.7 KB
Are these 2 right ? And are there any other possible Pseudo codes that are also correct ?
Attached files
Last edited by Leah.J; 1 year ago
0
reply
winterscoming
Badges: 19
Rep:
?
#2
Report 1 year ago
#2
I don't see any Pseudocode nor flowcharts in your post, but one way to check would be to trace through your flowchart using a trace table and an example/expected input/output, then to fill in the same trace table again using your pseuducode -- i.e. mentally testing your algorithm on paper by using a real example.
0
reply
Leah.J
Badges: 13
Rep:
?
#3
Report Thread starter 1 year ago
#3
(Original post by winterscoming)
I don't see any Pseudocode nor flowcharts in your post, but one way to check would be to trace through your flowchart using a trace table and an example/expected input/output, then to fill in the same trace table again using your pseuducode -- i.e. mentally testing your algorithm on paper by using a real example.
I just edited my post.
I tested them and to me they work, but I wouldn't know for sure ,
When I read the word stop, do I stop everything ? Because that would mean one of the two pseudo codes I wrote is wrong
0
reply
winterscoming
Badges: 19
Rep:
?
#4
Report 1 year ago
#4
(Original post by Leah.J)
I just edited my post.
I tested them and to me they work, but I wouldn't know for sure ,
When I read the word stop, do I stop everything ? Because that would mean one of the two pseudo codes I wrote is wrong
Both of your pseudocode listings are identical to each other. As long as "goto" is acceptable by your exam board, then they are correct - the position of STOP is fine, since 'STOP' indicates the end of the program, and logically the only way it can reach that is when I>N after the 'PRINT' instruction, so that's all fine because the rest of your logic is inside the ELSE block.

Normally, the problem with 'GOTO' is that it results in un-structured logic, which is why exam boards (and programmers generally) often won't accept it (although having seen your other post which uses 'goto' in the question's pseudocode, I wonder if that might not be the case with yours, in which case your pseudocode looks fine, as long as 'goto' is acceptable..)



In terms of other/alternative pseudocode, whenever you have a flowchart with an arrow which "loops" back on itself, that implies that you've got repetition/iteration (i.e. a loop) -- in which case you need to look at the flow of your program from the point of view of looking at which step(s) are potentially happening multiple times within that 'loop', because those will be the steps that belong inside a 'FOR' or 'WHILE'

(your visual flowchart actually makes it pretty clear to see where the loop is -- it shows three steps which are part of the closed loop that cycle back around on itself: the I>N boolean expression, the Fact=Fact*I instruction and the I=I+1 instruction. A lot like your ELSE block.

(the Pseudocode you have written is essentially the same thing that a compiler or interpreter would do when translating a FOR/WHILE loop from a language like Python or C++ into raw machine-code/assembly instructions -- computers like 'GOTO' but humans usually prefer things like for/while because it's usually easier to reason over.)


It's worth remembering how FOR and WHILE actually work -- i.e.
  • a 'WHILE' loop is able to repeatedly check a True/False expression then run some instructions each time that expression is True
  • a 'FOR' loop is like a more sophisticated/convenient WHILE loop used when the concept of 'counting' is involved, since it also includes steps which will create a counting variable and increment that variable.

(I don't know which exam board or which course you're on, but most of the exam boards seem to use much the same syntax with things like FOR/WHILE, so look at the "iteration" examples here: https://filestore.aqa.org.uk/resourc...8520-TG-PC.PDF )
Last edited by winterscoming; 1 year ago
0
reply
X

Quick Reply

Attached files
Write a reply...
Reply
new posts
Back
to top
Latest
My Feed

See more of what you like on
The Student Room

You can personalise what you see on TSR. Tell us a little about yourself to get started.

Personalise

Should there be a new university admissions system that ditches predicted grades?

No, I think predicted grades should still be used to make offers (675)
33.62%
Yes, I like the idea of applying to uni after I received my grades (PQA) (856)
42.63%
Yes, I like the idea of receiving offers only after I receive my grades (PQO) (386)
19.22%
I think there is a better option than the ones suggested (let us know in the thread!) (91)
4.53%

Watched Threads

View All