• 0

Pseudocode debugging help


Question

// This progam creates a screen with a textbox and a button.
// When the user clicks the button, a label displays the result
// which is 10% of the number in the textbox


start
   
  Declarations
      
    Screen screen1
      
    Button calcButton
      
    Textbox usersEntry
      
    Label result
   
  screen1.setSize(200, 200)
   
  calcButton.setText("Click to calculate 10% tax")
           calcButton.registerListener(calculateTax())
   
  screen1.add(usersEntry)
 

stop



calculateTax()
   
  Declarations
      
    Label result
      
    num RATE = 0.10
      
    string answer
   
  tax = usersEntry.getText() * RATE
   
  answer = "The tax is " tax   
  result.setText(answer)
   
  screen1.add(result)

return 

 

 

Are there anymore bugs? I'm kinda not understanding where the .getText comes from on here and think it might be a bug.

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

.getText() would be a method on a hypothetical Textbox class that returns the text content the user typed in.

 

Also, when writing Psuedocode, I'd write it more like this:

set Rate to 0.10
get Value from User
calculate Tax as Value * Rate
set Answer to "The tax is " + Tax
display Answer

You wouldn't normally start breaking things down into specific controls at this stage.

Link to comment
Share on other sites

  • 0

.getText() would be a method on a hypothetical Textbox class that returns the text content the user typed in.

 

Also, when writing Psuedocode, I'd write it more like this:

set Rate to 0.10
get Value from User
calculate Tax as Value * Rate
set Answer to "The tax is " + Tax
display Answer

You wouldn't normally start breaking things down into specific controls at this stage.

Thanks for the response. I don't understand why you need to add Tax on the answer though. Since it's asking for just the 10% wouldn't answer = "The Tax is" tax work?

Link to comment
Share on other sites

  • 0

It just depends on the kind of syntax that makes the most sense to you (there is no formal way of writing psuedocode).

 

When it comes to appending a value on to a string, I like to put a plus sign, but if you don't putting "The answer is " Tax is perfectly fine to.

Link to comment
Share on other sites

  • 0

It just depends on the kind of syntax that makes the most sense to you (there is no formal way of writing psuedocode).

 

When it comes to appending a value on to a string, I like to put a plus sign, but if you don't putting "The answer is " Tax is perfectly fine to.

 

 

I see, thanks. One last thing, in the code there is two label results declared. I'm thinking that only one is needed and the one inside the method should be removed? Would this be correct?

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.