none
Bank Calculator | ERROR Total is the Total + Input x 2

    Question

  • Hi,

    I am making a Bank Calculator with Bank Amount, Deposit Amount, Tax Percentage and Duration over years.

    It works fine until you get to the Total.

    EG ( Bank amount = 1 | Deposit amount = 1 | Tax = 0 | Duration = 10 |

    It would do

    Bank amount etc

    1: 1
    2: 2

    ETC

    Then

    Tax Paid = 0

    Total = 12 . It did Total + Input x 2

    BTW the Vars are old so that's why Tax is called Interest, Deposit is Principal. I tried Interest one before but I decided to do Tax and didn't change the Var

    CODE:

     
    maximumInterest = 50
    TextWindow.Write("Bank Total: ")
    bankTotalInput = TextWindow.ReadNumber()
    
    Path = Program.Directory
    Directory_Path = Path + "\resources"
    File_Path = Directory_Path + "\text.txt"
    Get_Path = File.GetDirectories(Directory_Path)
    File_Get_Path = File.GetFiles(Directory_Path + "text.txt")
    If Get_Path = "FAILED" or File_Get_Path = "FAILED" Then
      File.CreateDirectory(Directory_Path)
      File.WriteContents(File_Path, bankTotalInput)
      EndIf
    
    TextWindow.Write("Deposit Total: ")
    principalInput = TextWindow.ReadNumber()
    If principalInput < 0 Then
      TextWindow.WriteLine("Deposit cannot be negative")
      TextWindow.PauseWithoutMessage()
      Program.End()
    Else
      TextWindow.Write("Tax Percentage: ")
      interestInput = TextWindow.ReadNumber()
      If interestInput < 0 or interestInput = maximumInterest Then
        TextWindow.WriteLine("Interest cannot be negative or greater than " + maximumInterest)
      Else
        TextWindow.Write("Year duration: ")
        durationInput = TextWindow.ReadNumber()
        duration = durationInput
        bankInput = bankTotalInput
        TextWindow.WriteLine("")
        TextWindow.WriteLine("Bank Total Before = " + bankInput)
        TextWindow.WriteLine("Deposited = " + principalInput)
        TextWindow.WriteLine("Tax Percentage = " + interestInput + "%")
        TextWindow.WriteLine("Duration = " + duration + " years")
        TextWindow.WriteLine("")
          year = 1
      While year <= duration
        interestPaid = principalInput * (interestInput / 100)
        principalInput = principalInput - interestPaid
        TextWindow.WriteLine(year + ": - " + principalInput)
        year = year + 1
        principalInput = principalInput + bankInput
      EndWhile
        interestPaid = principalInput * (interestInput / 1000)
        total = principalInput - interestPaid + bankInput
        TextWindow.WriteLine("")
        TextWindow.WriteLine("Tax paid = " + interestPaid)
        TextWindow.WriteLine("Bank Total Now = " + total)
      EndIf
        
      TextWindow.WriteLine("")
      TextWindow.WriteLine("Press Any Key to terminate program")
      TextWindow.PauseWithoutMessage()
      Program.End()
    EndIf    


    I love coding. This is signature is 100% Original. :)



    Wednesday, February 15, 2017 8:51 AM

All replies

  • principalinput contains bankinput. In total you include bankinput a second time.

    Jan [ WhTurner ] The Netherlands

    Wednesday, February 15, 2017 10:48 AM
    Answerer
  • Forbidden Duck,

    Here's your program. I only had to comment out a few lines (3) that didn't work right. I left them there so you can figure out why they were causing problems.

    maximumInterest = 50
    TextWindow.Write("Bank Total: ")
    bankTotalInput = TextWindow.ReadNumber()
    Path = Program.Directory
    Directory_Path = Path + "\resources"
    File_Path = Directory_Path + "\text.txt"
    Get_Path = File.GetDirectories(Directory_Path)
    File_Get_Path = File.GetFiles(Directory_Path + "text.txt")
    If Get_Path = "FAILED" or File_Get_Path = "FAILED" Then
      File.CreateDirectory(Directory_Path)
      File.WriteContents(File_Path, bankTotalInput)
      EndIf
    TextWindow.Write("Deposit Total: ")
    principalInput = TextWindow.ReadNumber()
    If principalInput < 0 Then
      TextWindow.WriteLine("Deposit cannot be negative")
      TextWindow.PauseWithoutMessage()
      Program.End()
    Else
      TextWindow.Write("Tax Percentage: ")
      interestInput = TextWindow.ReadNumber()
      If interestInput < 0 or interestInput = maximumInterest Then
        TextWindow.WriteLine("Interest cannot be negative or greater than " + maximumInterest)
      Else
        TextWindow.Write("Year duration: ")
        durationInput = TextWindow.ReadNumber()
        duration = durationInput
        bankInput = bankTotalInput
        TextWindow.WriteLine("")
        TextWindow.WriteLine("Bank Total Before = " + bankInput)
        TextWindow.WriteLine("Deposited = " + principalInput)
        TextWindow.WriteLine("Tax Percentage = " + interestInput + "%")
        TextWindow.WriteLine("Duration = " + duration + " years")
        TextWindow.WriteLine("")
          year = 1
      While year <= duration
        'interestPaid = principalInput * (interestInput / 100)
        'principalInput = principalInput - interestPaid
        TextWindow.WriteLine(year + ": - " + principalInput)
        year = year + 1
        'principalInput = principalInput + bankInput
      EndWhile
      TextWindow.WriteLine("InterestInput: "+interestinput+" principleinput: "+principalinput)
        interestPaid = principalInput * (interestInput / 100)
        total = principalInput - interestPaid + bankInput
        TextWindow.WriteLine("")
        TextWindow.WriteLine("Tax paid = " + interestPaid)
        TextWindow.WriteLine("Bank Total Now = " + total)
      EndIf
       
      TextWindow.WriteLine("")
      TextWindow.WriteLine("Press Any Key to terminate program")
      TextWindow.PauseWithoutMessage()
      Program.End()
    EndIf


    JR

    Wednesday, February 15, 2017 11:41 AM
  • It still doesn't work

    I just counts 

    1: 1

    2: 1 

    3: 1

    ETC 

    I put in:

    Bank Amount = 1

    Deposit = 1

    Tax = 0



    I love coding. This is signature is 100% Original. :)

    Friday, February 17, 2017 4:57 PM
  • Please post the full program, and  what you have modified since the last time !

    Is your program dealing with simple interest or compound interest ?



    • Edited by YLedEditor Friday, February 17, 2017 10:14 PM
    Friday, February 17, 2017 10:12 PM
    Answerer
  • Forbidden Duck,

    In the "While year <= duration loop" move the endwhile to right after "TextWindow.WriteLine("Bank Total Now = " + total)" Then between the endwhile and the "TextWindow.WriteLine("Bank Total Now = " + total)" insert "bankInput = total". Then it will work.


    JR

    Friday, February 17, 2017 11:04 PM
  • Hi jricestk !
    Even with moving endwhile like you said, the answer is wrong: it still give 1049,50$.

    If you start with a Capital of 1000$ , adding a deposit of 50$ each year at 1% , in 5 years you should end with a capital of 1306,06 $

    here what your program give:


    • Edited by YLedEditor Friday, February 17, 2017 11:14 PM
    Friday, February 17, 2017 11:13 PM
    Answerer
  • "BTW the Vars are old so that's why Tax is called Interest, Deposit is Principal. I tried Interest one before but I decided to do Tax and didn't change the Var"

    This is what I put in the main question if you read it you would realize it's Tax not Interest


    I love coding. This is signature is 100% Original. :)

    Saturday, February 18, 2017 7:11 AM
  • This one isn't work but I think someone could fix this one. I had a working one before but I got rid of it because it was on my nervs because sometimes it would break

    All you need to fix is it to add it's numbers each year

    CODE:

    Start()
    Sub Start
      TextWindow.Write("Bank Total: ")
      bankTotalInput = TextWindow.ReadNumber()
      
      Path = Program.Directory
      Directory_Path = Path + "\resources"
      File_Path = Directory_Path + "\text.txt"
      Get_Path = File.GetDirectories(Directory_Path)
      File_Get_Path = File.GetFiles(Directory_Path + "text.txt")
      If Get_Path = "FAILED" or File_Get_Path = "FAILED" Then
        File.CreateDirectory(Directory_Path)
        File.WriteContents(File_Path, bankTotalInput)
      EndIf
      
      TextWindow.Write("Deposit Total: ")
      principalInput = TextWindow.ReadNumber()
      If principalInput < 0 Then
        TextWindow.Clear()
        TextWindow.WriteLine("Deposit cannot be negative")
        TextWindow.WriteLine("")
        TextWindow.WriteLine("Press any key to reset program")
        TextWindow.PauseWithoutMessage()
        TextWindow.Clear()
        Start()
      Else
        TextWindow.Write("Tax Percentage: ")
        interestInput = TextWindow.ReadNumber()
        If interestInput < 0 Then
          TextWindow.Clear()
          TextWindow.WriteLine("Tax cannot be negative")
          TextWindow.WriteLine("")
          TextWindow.WriteLine("Press any key to reset program")
          TextWindow.PauseWithoutMessage()
          TextWindow.Clear()
          Start()
        Else
          TextWindow.Write("Year Duration: ")
          durationinput = TextWindow.ReadNumber()
          If durationinput < 1 Then
            TextWindow.WriteLine("Year cannot be smaller than 1")
            TextWindow.WriteLine("")
            TextWindow.WriteLine("Press any key to reset program")
            TextWindow.PauseWithoutMessage()
            TextWindow.Clear()
            Start()
          ElseIf durationinput > 10 Then
            TextWindow.WriteLine("Year cannot be bigger than 10")
            TextWindow.WriteLine("")
            TextWindow.WriteLine("Press any key to reset program")
            TextWindow.PauseWithoutMessage()
            TextWindow.Clear()
            Start()
          EndIf
          duration = durationinput
          bankInput = bankTotalInput
          TextWindow.Clear()
          TextWindow.WriteLine("Bank Total Before = " + bankInput)
          TextWindow.WriteLine("Deposited = " + principalInput)
          TextWindow.WriteLine("Tax Percentage = " + interestInput + "%")
          TextWindow.WriteLine("Duration = " + duration + " years")
          TextWindow.WriteLine("")
          year = 0
          interestPaid = principalInput * (interestInput / 1000)
          principalInput = principalInput + bankInput
          While year <= duration
            principalInput = principalInput - interestPaid
            year = year + 1
            TextWindow.WriteLine(year + ": - " + principalInput)
          EndWhile
          total = principalInput - interestPaid
          TextWindow.WriteLine("Tax paid = " + interestPaid)
          TextWindow.WriteLine("Bank Total Now = " + total)
          TextWindow.WriteLine("")
          TextWindow.WriteLine("To Reset Program type (Reset)")
          TextWindow.WriteLine("To End Program type (End)")
          userendorreset = TextWindow.Read()
          If Text.ConvertToLowerCase(userendorreset) = "reset" Then
            TextWindow.Clear()
            Start()
          ElseIf Text.ConvertToLowerCase(userendorreset) = "end" Then
            Program.End()
          Else
            inr:
            TextWindow.Clear()
            TextWindow.WriteLine("Input Not Recognized")
            TextWindow.WriteLine("Try Again")
            TextWindow.WriteLine("")
            TextWindow.WriteLine("Type (Reset) to Reset Program")
            TextWindow.WriteLine("Type (End) to End Program")
            inr1 = TextWindow.Read()
            If Text.ConvertToLowerCase(inr1) = "reset" Then
              Goto inr
            ElseIf Text.ConvertToLowerCase(inr1) = "end" Then
              Program.End()
            Else
              Goto inr
            EndIf
          EndIf
        EndIf
      EndIf
    EndSub


    I love coding. This is signature is 100% Original. :)

    Saturday, February 18, 2017 7:39 AM
  • Yled and Forbidden Duck,

    In my comment above on moving the EndWhile I also said after that is moved to put     bankInput = total between the textwindow.writeline and the endwhile. If you do that it does work. Try Program VBF928.


    JR


    • Edited by jricestk Saturday, February 18, 2017 11:36 AM Edit
    Saturday, February 18, 2017 11:31 AM
  • Hi Forbidden Duck !


    • Edited by YLedEditor Saturday, February 18, 2017 3:17 PM
    Saturday, February 18, 2017 2:28 PM
    Answerer
  • Hi jricestk,

    In your program VBF928 above, with the same example , after five years, the answer should be

    1076,52$ . Your program give 1024,75 $.

    Use this web Compound Interest Calculator:

    http://moneychimp.com/calculator/compound_interest_calculator.htm

    the answer is:

    your program:


    • Edited by YLedEditor Saturday, February 18, 2017 3:00 PM
    Saturday, February 18, 2017 2:57 PM
    Answerer
  • Yled,

    I only wanted to change the program so that the math works as Forbidden Duck wrote it so that he could see what needed to be changed and learn from it. My intent was not to make it a compound interest program. The way that Forbidden Duck stated the program in the beginning is that a tax would be paid on the deposits. That is all this program does besides showing what the results are.

    Actually when you are putting money in a bank for saving the saver has generally paid tax on it from his earnings. He would be putting it in the bank for savings (interest) and safety. Then at the end of each year he would pay tax on the interest earned for the year for the whole account. So, then paying tax and earning interest makes it more challenging. So, we could make this more and more detailed, but then it would go beyond the original intent.


    JR

    Saturday, February 18, 2017 3:28 PM
  • As you can see in this topic:

    If you want to tell the computer what you want, YOU have to know what you want.


    Jan [ WhTurner ] The Netherlands

    Saturday, February 18, 2017 3:56 PM
    Answerer
  • Hi jricestk !

    If we want to calculate the income tax payable on the yearly  interest earned, it must still correctly calculated the amount of the annual interest earned. But, this program does not correctly calculate the annual interest. So we're going in circles, and we have to go back to square one.

    (1) build a program that correctly calculates a Principal p, for y years at an interest rate of i %.

    Then take the yearly interest and deduct the amount payable as income taxes.

    So if I go back to our example above, the first year, the interest amount is $ 10, suppose the income tax rate is 15%, then there will be ($ 10 x 15% =1,50 $ to be pay as in income tax.)


    Compound Interest Calculator



    1,00%
    15,00%
    Year Principal Yearly Deposit Interest Annual rate Balance Income Tax
    1 000,00 $ 1 000,00 $
    1 5,00 $ 10,00 $ 1 015,00 $ 1,50 $
    2 5,00 $ 10,15 $ 1 030,15 $ 1,52 $
    3 5,00 $ 10,30 $ 1 045,45 $ 1,55 $
    4 5,00 $ 10,45 $ 1 060,91 $ 1,57 $
    5 5,00 $ 10,61 $ 1 076,52 $ 1,59 $


    • Edited by YLedEditor Saturday, February 18, 2017 4:45 PM
    Saturday, February 18, 2017 4:38 PM
    Answerer
  • TextWindow.Write("Init $: ")
    sum = TextWindow.ReadNumber()
    TextWindow.Write("Add $ p.a.: ")
    add = TextWindow.ReadNumber()
    TextWindow.Write("Rate % p.a.: ")
    perc = TextWindow.ReadNumber()
    TextWindow.Write("Years: ")
    dur = TextWindow.ReadNumber()

    ' 'sum = sum * Math.Power(1 + perc/100, dur)    ' NO add
    For i = 1 To dur
      sum = sum * (1 + perc/100) + add
    EndFor
    TextWindow.WriteLine("Sum: "+ sum)
    TextWindow.WriteLine("")
    • Proposed as answer by YLedEditor Saturday, February 18, 2017 6:51 PM
    Saturday, February 18, 2017 6:33 PM
    Answerer
  • @Pappa Labub

    That's it ! right on !!

    Saturday, February 18, 2017 6:52 PM
    Answerer
  • Here is another example: A student start with 0.00$ in bank, and deposit 100$ each year, for 5 years at 2% Annual Interest rate:

    Here we are dealing with a :  Future Value of Annuity

    the formula is:

    In Small Basic  the formula is: 

    Fv=P*(Math.Power ((1+i),n)-1)/i

    program no: MDD747

    final answer: $520,40

                     Future Value of Annuity

       






    2,00%
    Year Principal Yearly Deposit Interest Annual rate Balance
    0,00 $ 0,00 $
    1 100,00 $ 0,00 $ 100,00 $
    2 100,00 $ 2,00 $ 202,00 $
    3 100,00 $ 4,04 $ 306,04 $
    4 100,00 $ 6,12 $ 412,16 $
    5 100,00 $ 8,24 $ 520,40 $

    Saturday, February 18, 2017 7:53 PM
    Answerer