943,724 Members | Top Members by Rank

Ad:
You are currently viewing page 1 of this multi-page discussion thread
Jan 15th, 2006
0

Trouble with figuring out the flowchart to pseudocode problem

Expand Post »
Hi, could someone to direct me the right way with this? Here is the problem, which I think I have nailed:

before:

	 A
	 if c then goto X
	 B
	 if d then goto Y
	 C
X:	 D
	 E
Y:	 F

after (in pseudocode):

A
if c then
  D
  E
else
  B
  if not d then
    C
    D
    E
F

Now I have a trouble with the flowchart I have attached.

Here is a pseudocode that I figured out, and I know it is wrong:

A
while c
  B
  if not d
    E
  else
    need to break out of wile loop somehow to get to 'F'
F

Please let me know if the first problem is right, and if you could help me with how to tame the flowchart to get rid of the arrow from d to F...

Thanks in advance,

Waldis
Attached Thumbnails
Click image for larger version

Name:	Homework-002---Problem-4.jpg
Views:	414
Size:	4.4 KB
ID:	1659  
Reputation Points: 30
Solved Threads: 0
Newbie Poster
waldis is offline Offline
24 posts
since Jan 2006
Jan 15th, 2006
0

Re: Trouble with figuring out the flowchart to pseudocode problem

First 2 are correct. last pseudocode is wrong.
I think it needs to be something like

A
if not c then b
while not d
{
   if not c then c
   D
   E
}
F
Reputation Points: 26
Solved Threads: 11
Posting Whiz in Training
f1 fan is offline Offline
275 posts
since Jan 2006
Jan 15th, 2006
0

Re: Trouble with figuring out the flowchart to pseudocode problem

sorry should not be a while loop just another if statement
A
if not c then b
if not d
{
   if not c then c
   D
   E
}
F
Reputation Points: 26
Solved Threads: 11
Posting Whiz in Training
f1 fan is offline Offline
275 posts
since Jan 2006
Jan 15th, 2006
0

Re: Trouble with figuring out the flowchart to pseudocode problem

Thanks for your input.

Now I got completely confused... from c down ir TRUE, and from d down is FALSE.

By saying c after 'if not c then' do you mean setting c to TRUE? And by D you mean d, and setting it's value to TRUE?

You made my brain boil, but I didn't get anywhere...

Thanks for your help,

Waldis
Reputation Points: 30
Solved Threads: 0
Newbie Poster
waldis is offline Offline
24 posts
since Jan 2006
Jan 15th, 2006
0

Re: Trouble with figuring out the flowchart to pseudocode problem

I think we both got confused. I wasnt too sure what A B C etc meant. Are they states in a state machine? Or just processes? also do they run though the flow once or keep repeating? I thought they might be function calls or something . So the if not c then c meant if your c flag hasnt been set then do c.
Reputation Points: 26
Solved Threads: 11
Posting Whiz in Training
f1 fan is offline Offline
275 posts
since Jan 2006
Jan 16th, 2006
0

Re: Trouble with figuring out the flowchart to pseudocode problem

I think i am with you now. i was confused between c and C and d and D. i take it A B C D E and F are some processes/functions etc. and c and d are flags?

In which case my pseudocode needs a minor modification i think
A
if not c then B
if not d
{
   if not c then C
   D
   E
}
F
Reputation Points: 26
Solved Threads: 11
Posting Whiz in Training
f1 fan is offline Offline
275 posts
since Jan 2006
Jan 16th, 2006
0

Re: Trouble with figuring out the flowchart to pseudocode problem

There is no 'C' or 'D', only 'c' and 'd', which are flags. A, B, E, and F are processes. When 'A' gets down to 'c' and flags it TRUE, it goes to 'B', if FALSE goes to 'F'. If we get to 'B' the next stop is a flag 'd', and if 'd' is TRUE it exits to 'F', if 'd' is FALSE it goes to 'E' and from 'E' goes back to the flag 'c' for another round if 'c' gets flagged TRUE.
The instructions was to modify the flowchart so the pseudocode could be written without GOTOs. And as I see the problem here is either the flag 'c' on the FALSE side or the flag 'd' on the TRUE side.

I hope I'm making sense here... and thanks for bearing with me.
Reputation Points: 30
Solved Threads: 0
Newbie Poster
waldis is offline Offline
24 posts
since Jan 2006
Jan 16th, 2006
0

Re: Trouble with figuring out the flowchart to pseudocode problem

Ok now i am totally lost. Your initial post had c and C and d and D but now you say there is no C or D? Your initial post also said if c is true to skip B but now you are saying if c is true to do B? Lets start again. I am with you that A B E F are processes and c & d are flags. Where do they get set? does the whole thing repeat?
Reputation Points: 26
Solved Threads: 11
Posting Whiz in Training
f1 fan is offline Offline
275 posts
since Jan 2006
Jan 16th, 2006
0

Re: Trouble with figuring out the flowchart to pseudocode problem

There were two problems at the beginning. The first problem was the code with GOTOs and the solution that I wrote was the second code I included. Then I have the second problem, for which I attached the scanned image of the flowchart I'm having problem with. What I'm talking about (with no C and D, only c and d) is this second problem from the flowchart.

And you said that the first problem, as I understood, is correct.
Reputation Points: 30
Solved Threads: 0
Newbie Poster
waldis is offline Offline
24 posts
since Jan 2006
Jan 16th, 2006
0

Re: Trouble with figuring out the flowchart to pseudocode problem

Ok, here is my solution for it:

A
i=TRUE
while c AND i
  if d then
    i=FALSE
  else
    E
F

All I had to do was add an additional flag where 'c' is, and if 'd' becomes FALSE, just skip 'E' and join the arrow going back to 'c', instead of going straight to 'F'.

I hope I'm making sense...

Waldis
Reputation Points: 30
Solved Threads: 0
Newbie Poster
waldis is offline Offline
24 posts
since Jan 2006

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Computer Science Forum Timeline: Applet for checking constructed DFA to recognize the set of strings
Next Thread in Computer Science Forum Timeline: Another pseudocode problem...





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC