• 0

Pseudocode Help!


Question

I am taking a basic programming class in college this semester. I am not learning a specific language in this class. He basically says follow the book as much as possible, but if it makes sense, you get credit.

 

I want to know if I can set up an If-Then-Else-If statement in this way?

If packages >= 10 AND packages <= 19 Then
     Display "You have a 20% discount" Then
          Set total = (99 * 0.2) + 99 Then
               Display total
Else If packages >= 20 AND packages <= 49 Then
     Display "You have a 30% discount" Then
          Set total = (99 * 0.3) + 99 Then
               Display total
End If

 

 

 

Also, this is not homework. This is just extra practice I am attempting on my own. I'm not trying to cheat! 

Link to comment
Share on other sites

10 answers to this question

Recommended Posts

  • 0

Individual statements that are not part of any logic structure don't require "then" at the end. Other than that, your psuedocode looks good to me.

Link to comment
Share on other sites

  • 0

The indentation makes no sense and the unnecessary "then"s everywhere either. Should be:

If packages >= 10 AND packages <= 19 Then
     Display "You have a 20% discount"
     Set total = (99 * 0.2) + 99
     Display total
Else If packages >= 20 AND packages <= 49 Then
     Display "You have a 30% discount"
     Set total = (99 * 0.3) + 99
     Display total
End If
Link to comment
Share on other sites

  • 0

 

The indentation makes no sense and the unnecessary "then"s everywhere either. Should be:

If packages >= 10 AND packages <= 19 Then
     Display "You have a 20% discount"
     Set total = (99 * 0.2) + 99
     Display total
Else If packages >= 20 AND packages <= 49 Then
     Display "You have a 30% discount"
     Set total = (99 * 0.3) + 99
     Display total
End If

 

Thank you, this helped a lot!

Link to comment
Share on other sites

  • 0

Nobody caught the fact that the more the item was discounted, the more expensive it gets? :p

I did notice that as well. Might want to double check that math, OP.

 

Also, I don't know if that's just a snippet of more, but you should pull display out of the ifs or you need an else to display it when there's no discount. Unnecessary code reduction is usually the better practice though. Try to put only code specific to that if inside the if.

Link to comment
Share on other sites

  • 0

Just an extra thing... Seeing as you're always displaying the total, just have one "Display Total" outside the IF conditional, and drop the others.  So:

If packages >= 10 AND packages <= 19 Then
     Display "You have a 20% discount"
     Set total = (99 * 0.2) + 99
Else If packages >= 20 AND packages <= 49 Then
     Display "You have a 30% discount"
     Set total = (99 * 0.3) + 99
End If
Display total

And yeah, fix your math! :p

 

Edit: I'm going blind, I missed AJerman's post! Sorry. :p

Link to comment
Share on other sites

  • 0

Just an extra thing... Seeing as you're always displaying the total, just have one "Display Total" outside the IF conditional, and drop the others.  So:

If packages >= 10 AND packages <= 19 Then
     Display "You have a 20% discount"
     Set total = (99 * 0.2) + 99
Else If packages >= 20 AND packages <= 49 Then
     Display "You have a 30% discount"
     Set total = (99 * 0.3) + 99
End If
Display total

And yeah, fix your math! :p

 

Edit: I'm going blind, I missed AJerman's post! Sorry. :p

Yeah I fixed the math I just didn't update it on here! :) 

Link to comment
Share on other sites

This topic is now closed to further replies.