• 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
https://www.neowin.net/forum/topic/1218195-pseudocode-debugging-help/
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.

  • 0
  On 16/06/2014 at 22:29, virtorio said:

.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?

  • 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.

  • 0
  On 16/06/2014 at 22:50, virtorio said:

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?

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

    • No registered users viewing this page.
  • Posts

    • Display Driver Uninstaller (DDU) 18.1.2.3 by Razvan Serea Display Driver Uninstaller (DDU) is a utility for completely removing AMD/NVIDIA/INTEL graphics drivers and related packages from your system, attempting to eliminate all leftovers (including registry entries, folders and files, driver store). Though AMD/NVIDIA/INTEL drivers can usually be removed via the Windows Control Panel, this uninstaller tool was created for situations where standard uninstall fails, or when you need to fully remove NVIDIA or ATI graphics card drivers. After using this driver cleaner, your system will behave as though it’s the first time you’re installing a new driver—similar to a fresh Windows installation. As with all such tools, we recommend creating a restore point beforehand, allowing you to undo changes if issues arise. If you're having trouble installing an older or newer driver, try it—there are reports that it resolves such problems. Recommended usage: The tool can be used in Normal mode but for absolute stability when using DDU, Safemode is always the best. Make a backup or a system restore (but it should normally be pretty safe). It is best to exclude the DDU folder completely from any security software to avoid issues. You do NOT need to uninstall the driver prior using DDU. Requirements: .NET Framework 4.8 Compatible with Windows 7, 8, 8.1, 10, and 11 (32-bit or 64-bit) Note: Using on Insider Preview builds is at your own risk. Display Driver Uninstaller (DDU) 18.1.2.3 changelog: All GPUs: Fixed hardware rescan issue when cleaning all GPUs without restarting or shutting down UI: Added Guru3D mention in the About section. General: Various fixes and enhancements. Download: Display Driver Uninstaller (DDU) 18.1.2.3 | 1.7 MB (Freeware) Download: DDU Portable | 1.2 MB Links: Display Driver Uninstaller Home Page | Screenshot | Forum Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • That would be nice, if excel could refresh pivot tables without bugs. Frequently you refresh a pivot and all parameters get lost. Now this will happen automatically. Bravo MS!
    • If one could ever put all the crap of the world in one box, that would be Microsoft.
    • The most corrupt and vile CEO any company ever had ! The only company that makes an insane amount of money decade after decade but doesn't deliver on even barely passable quality to customers, screws over partners and treats employees like trash
  • Recent Achievements

    • Dedicated
      Profit earned a badge
      Dedicated
    • One Month Later
      hhgygy earned a badge
      One Month Later
    • Week One Done
      hhgygy earned a badge
      Week One Done
    • One Year In
      NIKI77 earned a badge
      One Year In
    • Week One Done
      artistro08 earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      631
    2. 2
      ATLien_0
      237
    3. 3
      Xenon
      167
    4. 4
      neufuse
      146
    5. 5
      +FloatingFatMan
      123
  • Tell a friend

    Love Neowin? Tell a friend!