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

Recommended Answers

All 5 Replies

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.

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.

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.

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.