Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

Hi :)

I am really having problems with pseudocode as I have never had to use it before. I have been asked to write an algorithm in pseudocode that allows the user to input the selling prices of all homes in a town sold during 2009 and determine the median selling price. The median of a list of N numbers is as follows:

- the middle number of the sorted list, if N is odd

- the average of the two middle number in the sorted list, if N is even

The user will terminate the input by entering a zero or a negative number.

I would really appreciate any help and would be so grateful if somebody could explain how I go about this.

Thank you.

I am really having problems with pseudocode as I have never had to use it before. I have been asked to write an algorithm in pseudocode that allows the user to input the selling prices of all homes in a town sold during 2009 and determine the median selling price. The median of a list of N numbers is as follows:

- the middle number of the sorted list, if N is odd

- the average of the two middle number in the sorted list, if N is even

The user will terminate the input by entering a zero or a negative number.

I would really appreciate any help and would be so grateful if somebody could explain how I go about this.

Thank you.

Experts Exchange Solution brought to you by

Enjoy your complimentary solution view.

Get every solution instantly with Premium.
Start your 7-day free trial.

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

number = get_from_user()

number = number + 5

show(number)

or anywhere between these two extremes - as you prefer.

http://faculty.ccri.edu/mkelly/COMI1150/PseudocodeBasics.pdf

http://en.wikipedia.org/wiki/Pseudocode

http://polya.computing.dcu.ie/ca165/overview/lectures/w8/problemsolving/progdesign.pdf

www.cse.unr.edu/~bei/examples/pseudocodes/Pseudocode.doc

After reading these, and maybe finding other examples, then give it a try and post your results.

Thank you

number = get_from_user()

/*

Ask user to input the selling prices of all homes sold in 2009

To terminate list ask user to enter zero

Array sort

/*Sort list into ascending order

Count numbers input

If N is odd – output middle number

If N is even – find average of two middle numbers and output

Does this look more like it? I have been searching for help with pseudocode for hours now as we only had a brief lecture on it which wasn't really very in depth so I'm not really too sure how much infomation I actually need to add and if I need to add the actual code so I'm sorry if this doesn't make much sense.

number = get_from_user()

/* Ask user to input numbers

Question 4

number = get_from_user()

/*

WHILE number >0 Ask user to input the selling prices of all homes sold in 2009

ENDIF

To terminate list ask user to enter zero

Array sort

/*Sort list into ascending order

Count numbers input

If N is odd – output middle number

If N is even – find average of two middle numbers and output

That depends on the audience the pseudo code is intended for. If it's just for yourself, then you add as much information as you need. If it's for someone else, then you have to consider what level of detail the other person(s) might require. In the case of an assignment for example, you'd usually need a relatively high level of detail.

>> if I need to add the actual code

pseudo code is a way to quickly write down how something should work, before actually writing the code. So, you don't add actual code in there (unless it's easier to express an idea that way).

One thing I notice, is that you seem to be adding comments in your pseudo code. Don't do that : the whole idea of pseudo code is that it should be self-descriptive enough, so no comments are needed.

And some specific notes :

>> number = get_from_user()

what's this line there for ?

>> WHILE number >0 Ask user to input the selling prices of all homes sold in 2009

A few remarks here :

(a) use multiple lines to express separate ideas. If you have a loop, then make sure that the loop body is on separate lines between the start and end of the loop

(b) think carefully about what happens in each iteration. Currently you say, that for every iteration, you ask the user to inpu the selling prices of all homes. That's not what should be happening - for each iteration, you should ask the selling price of only one home

(c) for each iteration, there's a bit more going on than just asking for the selling price of a home. You need to also do something with that selling price.

>> To terminate list ask user to enter zero

The user needs to know this information before entering the loop. Otherwise, he won't know how to stop.

Okay - well here's my next attempt when taking into account the advice you gave me:

DECLARE Price, N

DISPLAY “Please input the selling price of the home sold in 2009. To terminate the input you must enter a zero”

GET Price

Store total of numbers input (N)

WHILE Price >0

DISPLAY “Please input the price of another home sold in 2009”

ENDIF

When the user has entered the zero to terminate the input count numbers input (N)

Sort input numbers into a list in ascending order

If N is odd the Median = middle number of the sorted list

DISPLAY “The median selling price of house sold in 2009 is:” + Median

ELSE

If N is even the Median = the average of two middle numbers of the sorted list

DISPLAY “The median selling price of house sold in 2009 is:” + Median

You don't know the amount of values input yet - you'll know that after the loop

>> DISPLAY “Please input the price of another home sold in 2009”

You'll also have to actually get the input, and store it somewhere

>> When the user has entered the zero to terminate the input count numbers input (N)

You don't need to explicitly say "When the user has entered the zero to terminate the input" - that is implicit from the while loop just before it. No need to be too verbose ;)

>> DISPLAY “The median selling price of house sold in 2009 is:” + Median

You have this line twice - you could have it only once ... :)

DISPLAY “Please input the selling price of the home sold in 2009. To terminate the input you must enter a zero”

GET UserInputPrice

WHILE UserInputPrice >0

DISPLAY “Please input the price of another home sold in 2009”

ENDIF

ADD UserInputPrice to (N) PriceList

COUNT numbers input

SORT PriceList (N)

If (N) PriceList % 2 == 0 (Even)

medianPrice = ( PriceList[N/2] + PriceList[N/2 + 1 ] ) / 2 (Average the middle two prices)

ELSE

medianPrice = ( PriceList[N/2 + 1] (Get the middle price)

DISPLAY “The median selling price of house sold in 2009 is:” + medianPrice

>> WHILE UserInputPrice >0

>> DISPLAY “Please input the price of another home sold in 2009”

>> ENDIF

You still have a loop that just asks the user to input a price. You don't actually get the price, or do anything with it.

>> ADD UserInputPrice to (N) PriceList

Are you sure about the location of this statement ? Think about what it does, and when it should happen ... Should it be executed more than once ?

Does this look any better?

DISPLAY “Please input the selling price of the home sold in 2009. To terminate the input you must enter a zero.”

GET UserInputPrice

ADD UserInputPrice to (N) PriceList

WHILE UserInputPrice >0

DISPLAY “Please input the price of another home sold in 2009.”

ADD UserInputPrice to (N) PriceList

ENDIF

You're not a nuisance at all ! I wouldn't sign up as expert on this site, if I wasn't prepared to help people out however I can :)

>> Does this look any better?Does this look any better?

Looks a lot better. But you probably also want to get the price inside the while loop. Otherwise the user enters it for nothing ;)

I was just wondering - is the price not inside the loop from when I did:

ADD UserInputPrice to (N) PriceList

Inside the loop, you just have 'ADD UserInputPrice to (N) PriceList', so you just add a price to the list - you don't actually get the new input price from the user.

I guess this is how I should have done it then?:

Question 4

DISPLAY “Please input the selling price of the home sold in 2009. To terminate the input you must enter a zero.”

GET UserInputPrice

ADD UserInputPrice to (N) PriceList

WHILE UserInputPrice >0

DISPLAY “Please input the price of another home sold in 2009.”

GET UserInputPrice

ADD UserInputPrice to (N) PriceList

ENDIF

COUNT numbers input

SORT PriceList (N)

If (N) PriceList % 2 == 0 (Even)

medianPrice = ( PriceList[N/2] + PriceList[N/2 + 1 ] ) / 2 (Average the middle two prices)

ELSE

medianPrice = ( PriceList[N/2 + 1] (Get the middle price)

DISPLAY “The median selling price of house sold in 2009 is:” + medianPrice

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trialI thank you SO, SO much for your help - you have no idea how much this was getting to me, once again THANK YOU :)

Algorithms

From novice to tech pro — start learning today.

Experts Exchange Solution brought to you by

Enjoy your complimentary solution view.

Get every solution instantly with Premium.
Start your 7-day free trial.

For example :

get number from user

increment number by 5

show number

Try giving it a go, and see what you can come up with. You can then post it here, and we'll have a look at it for you.