locked
Checkbook Balancer RRS feed

  • Question

  • Hey everyone.  I'm making a checkbook balancer and I am pretty much finished.  The import ID is: QKQ121 .  The question asks for your balance, then it goes to subtraction, where it takes funds that were deducted for multiple reasons and outputs your subtotal until you put in the input that you are finished subtracting and adding everything.  But, in the subtraction part (toward the bottom, line 92 is where it starts), when you input a to go to "add" or d to go to "done" the program stops.  If someone could fix this problem that would be awesome.  If there are any other errors you find please fix them also.

     

    Thanks,

    Tom

    • Edited by TomRox Tuesday, July 6, 2010 9:48 PM
    Tuesday, July 6, 2010 8:33 PM

Answers

  • Here is a modified version of your program using subroutines - they serve 2 purposes:

    1] to make the structure clearer - each subroutine should do only one thing

    2] allow us to use the same code without rewriting it several times like ShowBalance()

    It is good to add comments that describe the intent , not just what it does since the code itself does this.  For example:

    balance = 0.01*Math.Floor(100*balance + 0.5) 'Round to nearest cent

    Import QKQ121-1

    • Proposed as answer by litdev Saturday, July 10, 2010 5:53 PM
    • Marked as answer by litdev Monday, July 12, 2010 5:58 PM
    Tuesday, July 6, 2010 9:59 PM

All replies

  • Nice program,

    At line 104 we have:

    TextWindow.WriteLine("Are we going to subtract more, add, or are we done (a/s/d)")
    moretotract = TextWindow.Read()

    then we check moretotract and GoTo subtract if we enter s , otherwise we check the value of the variable choice2 .  This variable was used earlier, but was not the variable entered on line 105 (above).

    Change line 113  and line 119 to respecitvely:

    If (moretotract = "a")Then

    If (moretotract = "d")Then

    Also when we have done an add, later we have:

    begin:
    Goto done
    done:
    absolute = total
    TextWindow.WriteLine("Your total is: "+absolute)
    TextWindow.WriteLine("Are you ready to end the program (y/n): ")
    endprogram = TextWindow.Read()
    If (endprogram = "y")Then
      Goto end
    Else
      Goto begin
    EndIf
    end:

    If we follow the logic and enter "n" we GoTo begin, then GoTo done and get asked the same question again, i.e. pressing 'n' gets us nowhere, just the same question again.

    Think about using subroutines to do the specific tasks like adding, subtracting etc and try to reduce the GoTo's to control the program logic.  This isn't necessarily critical for this program, but will help to develop good habits helpful for larger projects.  Start with a small program to get the idea of using subroutines effectively.

    Good luck.

    Tuesday, July 6, 2010 8:54 PM
  • TomRox,

    Here's an example of your subroutine that will work as explained by litdev.  I put in the "s" or "S" part to have it test for either uncapitalized or capitalized.  Keeps people from wondering why it isn't working when they know they're hitting the right key.

    Jricestk 

    startatsub:
    If moretotract = "s" or "S" Then
      Goto subtract
    Elseif  moretotract = "a" or "A" then
      goto add
    ElseIf moretotract = "d" or "D" then
      Goto done
    Else
      Goto startatsub
    EndIf

     

    Tuesday, July 6, 2010 9:07 PM
    Answerer
  • Thank you so much!  All fixed!

     

    Awesome dude,

    Tom

    Tuesday, July 6, 2010 9:48 PM
  • Here is a modified version of your program using subroutines - they serve 2 purposes:

    1] to make the structure clearer - each subroutine should do only one thing

    2] allow us to use the same code without rewriting it several times like ShowBalance()

    It is good to add comments that describe the intent , not just what it does since the code itself does this.  For example:

    balance = 0.01*Math.Floor(100*balance + 0.5) 'Round to nearest cent

    Import QKQ121-1

    • Proposed as answer by litdev Saturday, July 10, 2010 5:53 PM
    • Marked as answer by litdev Monday, July 12, 2010 5:58 PM
    Tuesday, July 6, 2010 9:59 PM