
-----------------------------------
kyoshiro
Fri Dec 12, 2003 12:02 am

procedure problem
-----------------------------------
I need to write a procedure that gets numbers from the user and display the mode (most frequently occurring number).

To begin i asked the user for the number of numbers he/she is going to enter. Then in a for loop, i stored the numbers in the array. I then passed this into a procedure.

Now the problem lies is how i can find the mode. I had an idea of finding the greatest number and smallest number in the array. Then creating a new array with values from smallest to greatest. Then i can compare the values of my 1st array from user and with my new array. Then i can set a "if statement" if the numbers from the 1st array = my new array.. then i can add a counter. In the end of all this looping... i can then compare the values of the counter and display the mode.. 

This basic algorithm.. is all i have so far. Could anyone perhaps propose a better idea of a program to solve this problem or perhaps show me the source code :-)

ty in advance  :P  :P

-----------------------------------
AsianSensation
Fri Dec 12, 2003 12:10 am


-----------------------------------
sort the list, once the list is sorted, all you have to do is keep a counter. increase the counter if the element in the array is equal to the previous. Once the element aren't equal, record the value in the counter and then reset the counter, keep on doing this until you went through the array.

-----------------------------------
McKenzie
Fri Dec 12, 2003 4:40 am

Re: procedure problem
-----------------------------------
This basic algorithm.. is all i have so far. Could anyone perhaps propose a better idea of a program to solve this problem or perhaps show me the source code :-)
Umm...I think you forgot to attach the code you were working on.  AZN's way works. I prefer to handle it a little different.
1. Count how many times each element occurs (using and array of counters)
e.g.
original  : 4 3 4 5 6 3 2 4
counters: 3 2 3 1 1 2 1 3
2. Find the position of the highest number in the counter array.
3. Result the original at the same position (I know you said procedure, but it works better as a function)

-----------------------------------
DanShadow
Fri Dec 12, 2003 4:23 pm


-----------------------------------
hmmm... if  I understood the question correctly...this might work.
make an  array (counter) and a variable (intin) and an array (numbers). Then in a "for" statement, (1..length (numbers)) asking for numbers, then adding them to the array. 
for i:1..length(numbers)
put "Enter a number: "..
get intin
numbers(i):=intin
end for
^^Use something like that, then at the end, have a "for" statement that goes through the numbers array, and adds to the "counter" array whenever a number is found twice or more. then check the "counter" arra y, see which is highest...like 
for i:1..length(counter)
if counter(i)>greatest_num then
greatest_num:=counter(i)
end if
end for
^^Like that...I hope you get the idea

-----------------------------------
Andy
Fri Dec 12, 2003 5:42 pm


-----------------------------------
dude, your method is not as good as azns... read his. its so much more effiecient... u should read other ppl's replies before posting your own cuz if you dont have anything better, dont bother posting it

-----------------------------------
AsianSensation
Fri Dec 12, 2003 7:25 pm


-----------------------------------
come on andy, not even Asok was that harsh, be a bit more positive, it will make the world a much better place. Seriously though, saying other people's code "sux" or "gay" doesn't solve the problem. Good thing you don't have powers in the Turing forum, if you did, next thing we know, dodge comes here blazing with all the flamethrower and guns you could possibly have.

-----------------------------------
Mazer
Fri Dec 12, 2003 7:45 pm


-----------------------------------
tru dat, AsianSensation, tru dat.

dodge - i'm disappointed in you. you've strayed from the path of the whatdotcolor warrior.

-----------------------------------
Andy
Fri Dec 12, 2003 8:31 pm


-----------------------------------
wtf are u guys talking about? i did no such thing

-----------------------------------
McKenzie
Fri Dec 12, 2003 11:39 pm


-----------------------------------
Hmmm ...  :shock: 
am I the "dude" you're talkn'(typin') bout  :?: 
harsh dodge, harsh ...
I'll try better next time  :wink:

-----------------------------------
Andy
Sat Dec 13, 2003 4:55 pm


-----------------------------------
no sir it was danshadow, and how was i harsh?
