Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Median
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Tallguy




PostPosted: Fri Mar 28, 2008 1:15 pm   Post subject: 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 Cool *



median.t
 Description:

Download
 Filename:  median.t
 Filesize:  4.24 KB
 Downloaded:  184 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
SIXAXIS




PostPosted: Fri Mar 28, 2008 10:10 pm   Post subject: 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




PostPosted: Fri Mar 28, 2008 10:21 pm   Post subject: 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




PostPosted: Sat Mar 29, 2008 4:02 pm   Post subject: RE:Median

this was my first time doing sorting, so i'm still kinda new at it . . .
michaelp




PostPosted: Sat Mar 29, 2008 4:08 pm   Post subject: RE:Median

What do you mean +600 lines? It's 261 lines. And that's with comments.
Still nice though, for a first time. Very Happy
Tallguy




PostPosted: Thu Apr 03, 2008 8:28 am   Post subject: RE:Median

ty
Zampano




PostPosted: Thu Apr 03, 2008 4:18 pm   Post subject: 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




PostPosted: Tue Apr 08, 2008 7:32 am   Post subject: RE:Median

how would i use an array to get the median for any amount of numbers the user enters?
Sponsor
Sponsor
Sponsor
sponsor
Carey




PostPosted: Tue Apr 08, 2008 11:10 am   Post subject: 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




PostPosted: Wed Apr 09, 2008 1:39 pm   Post subject: 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




PostPosted: Wed Apr 09, 2008 2:32 pm   Post subject: 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




PostPosted: Thu Apr 10, 2008 11:16 am   Post subject: 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
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 12 Posts ]
Jump to:   


Style:  
Search: