
-----------------------------------
Tallguy
Fri Mar 28, 2008 1:15 pm

Median
-----------------------------------
wat up ppl? this is a very simple program 
 -the user enters 4 numbers
-sorts number from least to greatest
-puts the median
enjoy, anyone may use

*how would i modify this to make it alphablize words?, plz comment  8-) *

-----------------------------------
SIXAXIS
Fri Mar 28, 2008 10:10 pm

Re: Median
-----------------------------------
Not sure about making it do letters, but I have a suggestion. You can make it do unlimited numbers by taking away the variables like n1, n2, n3, etc. and making it an array. Do this and the user can input the amount of numbers they want or you can even have it set to unlimited. You would use a for loop to have it reorder the numbers. I would do it for you, but I'm kind of busy right now.

-----------------------------------
Mackie
Fri Mar 28, 2008 10:21 pm

RE:Median
-----------------------------------
This program works but it should defiantly not be +600 lines. There is a lot of optimization. First off to sort the numbers you could do a very simple bubble sort (wikipedia).

-----------------------------------
Tallguy
Sat Mar 29, 2008 4:02 pm

RE:Median
-----------------------------------
this was my first time doing sorting, so i'm still kinda new at it . . .

-----------------------------------
michaelp
Sat Mar 29, 2008 4:08 pm

RE:Median
-----------------------------------
What do you mean +600 lines? It's 261 lines. And that's with comments.
Still nice though, for a first time. :D

-----------------------------------
Tallguy
Thu Apr 03, 2008 8:28 am

RE:Median
-----------------------------------
ty

-----------------------------------
Zampano
Thu Apr 03, 2008 4:18 pm

Re: Median
-----------------------------------
To do this with letters, look at the ord() function. It will give 65 unto 91 for smallercase letters and  . . . something else for capitals. The integer returned is the letter's spot in ASCII and the number formed from the binary of the byte used to represent the letter.

-----------------------------------
Tallguy
Tue Apr 08, 2008 7:32 am

RE:Median
-----------------------------------
how would i use an array to get the median for any amount of numbers the user enters?

-----------------------------------
Carey
Tue Apr 08, 2008 11:10 am

RE:Median
-----------------------------------
That question has already been answered. Just make the array flexible (look in the help file), sort it, then if the number of items is odd print the middle. if even print the average of the 2 middle ones

-----------------------------------
Tallguy
Wed Apr 09, 2008 1:39 pm

RE:Median
-----------------------------------
this is wat i have now, wat do i do next?
%Alex van der Mout
%4/9/08
%OBJECTIVE - Write a program which
%calculates the median value in a
%list of numbers. Have the user enter
%the number of items in the list and
%all of the values they want the median of.

var number : int
var sort:real

put "How many numbers are there? " ..
get number

var list : array 1 .. number of int%%%%%%gets numbers
put "What are the numbers?"
for i : 1 .. number
    get list (i)
end for%%%%%%%%%%%%%%%end gets

put "The numbers in order are . . . " %%%%%%%%%sorts numbers
var sortlist : array 1 .. number of int
for i : 1 .. number
    var smallest := 999
    var where : int
    for j : 1 .. number
        if list (j) < smallest then
            smallest := list (j)
            where := j
        end if
    end for
    sortlist (i) := smallest
    list (where) := 999
end for
for i : 1 .. number
    put sortlist (i)
end for%%%%%%%%%%%%%%%%%%%%%%%%end sorts
put ""

-----------------------------------
Nick
Wed Apr 09, 2008 2:32 pm

RE:Median
-----------------------------------
if I remember math than median is the middle, so if you have an array 1.. number, how would you find the middle?

hint: put sortlist(simple math)

-----------------------------------
Tallguy
Thu Apr 10, 2008 11:16 am

RE:Median
-----------------------------------
i got it to work . . .

%Alex van der Mout
%4/9/08
%OBJECTIVE - Write a program which
%calculates the median value in a
%list of numbers. Have the user enter
%the number of items in the list and
%all of the values they want the median of.

var number : int
var sort : real
var position : int
put "How many numbers are there? " ..
get number

var list : array 1 .. number of int %%%%%%gets numbers
put "What are the numbers?"
for i : 1 .. number
    get list (i)
end for %%%%%%%%%%%%%%%end gets

put "The numbers in order are . . . " %%%%%%%%%sorts numbers
var sortlist : array 1 .. number of int
for i : 1 .. number
    var smallest := 999
    var where : int
    for j : 1 .. number
        if list (j) < smallest then
            smallest := list (j)
            where := j
        end if
    end for
    sortlist (i) := smallest
    list (where) := 999
end for
for i : 1 .. number
    put sortlist (i)
end for %%%%%%%%%%%%%%%%%%%%%%%%end sorts
put ""

if number mod 2 = 0 then
    put "Here is your Median"
    position := round (number / 2)
    put (sortlist (position) + sortlist (position + 1)) / 2
else
    position := ceil (number / 2)
    put "Here is your Median"
    put sortlist (position)
end if
