0

need help writing pseudocode
input origprice
set discount = price * 0.20
set finalprice = origprice - discount
output final
stop

3
Contributors
5
Replies
12
Views
3 Years
Discussion Span
Last Post by deceptikon
0

Oh, the mods would have moved it for you! (or you could have PM'd one)

As I said in my last post:

The only problem I see with your pseudocode is that price should be written as origprice.

0

need help writing pseudocode

You've already done it. Barring a minor inconsistency where you create one variable name but use another (ie. origprice/price and finalprice/final), what you've posted is legitimate pseudocode.

0

was the pseudocode put in the right order because I wasn't sure thats why I was trying to get hlp with this one I thought I did something very wrong.

0

so once I moved the price origPrice the whole code would have been in the correct format

0

was the pseudocode put in the right order because I wasn't sure thats why I was trying to get hlp with this one I thought I did something very wrong.

Nope, it looks good. Once you fix the "semantic" errors it's solid logic:

input origprice
set discount = origprice * 0.20
set finalprice = origprice - discount
output finalprice
stop

You could simplify the language by removing the set keyword and assuming that the end of the file is equivalent to a stop keyword:

input origprice
discount = origprice * 0.20
finalprice = origprice - discount
output finalprice

Or by combining the variables into a single expression:

input origprice
output ((origprice * 0.20) - discount)

But all in all, what you have is fine.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.