View Full Version : Flowcharts from hell
Nuclear Krusader
02-03-2004, 06:34 PM
Howdy fellows,
Can you give me a hand with these insufferable flowcharts for tomorrow's assignment?
The problem is this one:
Reads in a list of positive numbers (use -1 to represent the end of the list) and prints out the largest and the second largest numbers. (Assume that the list contains at least two numbers.)
This is (http://www3.sk.sympatico.ca/keitel/Problem2.pdf) what I have so far. But I cannot find a way to read in the second number, compare it and print it out as the second largest.
Any ideas?
TIA
Nuclear Krusader
02-03-2004, 07:28 PM
And the third one is even worse:
Based on 2, find the largest number, the second largest number, and their positions in a list of positive numbers. Assume now that the end_of_list tag is "-1".
Given the following data:
10 30 10 20 40 -1,
the results are:
The largest number is 40 at position 5
The second largest number is 30 at position 2.
:confused: :confused:
homer15
02-03-2004, 07:38 PM
this is what i came up with for problem 2... it's in excel... i've never worked with flowcharts before, so sorry if it's wrong.
hobey19
02-03-2004, 08:27 PM
link is not working for me, don't know if you took it down or what
craig
Nuclear Krusader
02-03-2004, 08:45 PM
Strange, I haven't moved it and it's working from this side.
hobey19
02-03-2004, 09:08 PM
just tried it on another computer and it is still not working. oh well, sorry i could not help
craig
Nuclear Krusader
02-03-2004, 09:11 PM
Here.
Nuclear Krusader
02-03-2004, 10:59 PM
Thank you Dok, Hobey and Homer. I got the first one, flowchart and code. :)
Now, I only have to find a way to keep track of the entered number positions.
Any suggestions?
TwoRails
02-03-2004, 11:25 PM
Originally posted by Nuclear Krusader
And the third one is even worse:
Based on 2, find the largest number, the second largest number, and their positions in a list of positive numbers. Assume now that the end_of_list tag is "-1".
Given the following data:
10 30 10 20 40 -1,
the results are:
The largest number is 40 at position 5
The second largest number is 30 at position 2.
:confused: :confused: Well, I didn't see the "based on" part until I finish my little diddie. Attached is some Pseudo code for you. You should be able to easily transform it to a flowchart.
Hope the attached is what you are looking for!
TwoRails
homer15
02-04-2004, 01:00 AM
on the first problem, don't you want it to output two different numbers? you'd need two variables, then, instead of just the one output.
Nuclear Krusader
02-04-2004, 01:05 AM
OK.
Here's (http://www3.sk.sympatico.ca/keitel/Problem2final.pdf) the final version of the first problem.
And its C++ code:
Nuclear Krusader
02-04-2004, 01:07 AM
Now, the second one I'm having problems with.
The values are right, and so is the position for the largest one, but the second largest one always reports 1 as its position.
Here's the flowchart (http://www3.sk.sympatico.ca/keitel/Problem3.pdf)
And here's the code:
DarkHorse
02-04-2004, 09:19 AM
if (number>highest)
{
position1=counter;
second_highest=highest;
highest=number;
}
If you already have a value for position1 you need to bump it down to position2, as it was the previous highest and now is only second highest. You notice you already sent the value (second_highest=highest; ), now you need to send the position with it.
Nuclear Krusader
02-04-2004, 09:05 PM
Thank you all for your help, fellows. I finally got them all sorted out. :)
vBulletin® v3.7.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.