Compound Interest calculator is not giving right answer

Discussion in 'Requests' started by auruem, Aug 18, 2020.

    
  1. auruem

    auruem Member


    Dear Experts

    This code of interest calculator is not giving right answer in compound interest calculation,
    when selected interest rate as 5% or less ( it gives simple interest result)

    else it gives right answer, in both simple and compount interest calculation.

    also suggest is tally have a predefine formula for compound interest calculation.

    please help

    Code:
        [#Menu: Gateway of Tally]
            Title        : "Calculators"   
            Add    : Key Item    : Before : @@locQuit    : Calculator     : N : Menu    : Calculator
    
        [Menu: Calculator]
            Title        : "Goodwill Learning World"   
            Indent        : "Calculators"
            Item        : Blank
            Key Item    : Simple Interest            : S : ALTER        : Simple Intrest Calculator
            Key Item    : Compound Interest            : C : ALTER        : Compound Interest Calculator
            Item:Calculator:Browse:"calc.exe"
    
        [Report: Compound Interest Calculator]
            Use    : Simple Intrest Calculator
            Local    : Form    : Interest Calc        : Local        : Field    : Form SubTitle    : Info    : "Compound Interest Calculator"
            Local    : Line    : Interest Result    : Local        : Field    : Medium Prompt    : Info    : "Compound Interest Amount :"
            Local    : Field    : Interest Result    : Set As    : $$CIExpCalc:#InterestPrincipal:#InterestRate:#InterestNoOfYrs
    
    
    
    
    ;; Function to calculate Compound Interest
    
        [Function: CIExp Calc]
    
    ;; Definition Block
        Parameter    : P        : Amount
        Parameter    : R        : Number
        Parameter    : T        : Number
        Returns        : Amount
    
        Variable    : Interest    : Amount
        Variable    : IntPYear    : Amount
        Variable    : Counter    : Number
    
    ;; Procedural Block
    
        01 : SET    : Counter    : 0
        02 : SET    : Interest    : 1
        03 : SET    : Interest    : (1 + (##R/100))
        05 : SET    : Interest    : $$Exponential:##Interest:##T
        06 : SET    : Interest    : (##P * ##Interest) - ##P
        07 : RETURN    : ##Interest
    
        [Function: Exponential]
            Parameter    : X         : Amount
            Parameter    : T        : Number
            Returns        : Amount
       
            Variable    : ExpResult    : Amount
            Variable    : Counter    : Number
    
            01 : SET     : Counter    : 0   
            02 : SET    : ExpResult    : 1
    
            03 : WHILE    : (##Counter < ##T)
            04 :     SET            : ExpResult        : ##ExpResult * ##X
            05 :     INCREMENT    : Counter
            06 : END WHILE
       
            07 : RETURN    : ##ExpResult
    
    
    
        [Report: Simple Intrest Calculator]
            Form    : Interest Calc
            Auto    : Yes
    
        [Form: Interest Calc]
            Parts    : Form SubTitle, Interest Calc
            Local    : Field    : Form SubTitle        : Info        : "Simple Intrest Calculator"
            Width    : 30% Page
       
        [Part: Interest Calc]
            Lines    : Interest Principal, Interest Rate, Interest NoOfYrs, Interest Result
    
        [Line: Interest Principal]
            Fields    : Medium Prompt, Interest Principal
            Local    : Field    : Medium Prompt    : Info        : "Principal Amount :"
    
        [Field: Interest Principal]
            Use            : Amount Field
    
        [Line: Interest Rate]
            Fields    : Medium Prompt, Interest Rate
            Local    : Field    : Medium Prompt    : Info        : "Rate :"
    
        [Field: Interest Rate]
            Use            : Number Field
            Format        : "No Zero, Percentage"
            Align        : Right
            Width       : @@AmountWidth
    
        [Line: Interest NoOfYrs]
            Fields    : Medium Prompt, Interest NoOfYrs
            Local    : Field    : Medium Prompt    : Info        : "Period :"
    
        [Field: Interest NoOfYrs]
            Use            : Number Field
            Format        : "NoZero"
            Align        : Right
            Width       : @@AmountWidth
    
        [Line: Interest Result]
            Fields    : Medium Prompt, Interest Result
            Local    : Field    : Medium Prompt        : Info        : "Simple Interest Amount :"
            Local    : Field    : Default        : Inactive    : $$IsEmpty:#InterestPrincipal OR $$IsEmpty:#InterestRate OR $$IsEmpty:#InterestNoOfYrs
            SpaceTop: 1
    
            [Field: Interest Result]
                Use            : Amount Field
                Set Always    : Yes
                Set As        : $$SICalc:#InterestPrincipal:#InterestRate:#InterestNoOfYrs
    
    [Function: SI Calc]
    
        Parameter    : P            : Amount
        Parameter    : R            : Number
        Parameter    : T            : Number
        Returns        : Amount
        Variable    : Interest    : Amount
        01 : SET    : Interest    : (##P * ##R * ##T) / 100
        02 : RETURN    : ##Interest
     


  2. Himanshu-2002

    Himanshu-2002 Active Member


    You Made This Code ?...In last post you said...you are not good at function and now See you are using function like a pro...If you done this then I am damn sure you know how to solve it
     


  3. auruem

    auruem Member


    yes it's true it's very hard for me to learn function of functions

    got this some where on net

    might be on goodwill learning world youtube
     


  4. Amit Kamdar

    Amit Kamdar Administrator Staff Member


    It is not Goodwill's either.........they just collect codes and post it.

    This TDL is available in the sample folder.

    You can find it in .....Samples\User Defined functions folder.

    Given below.... the compound Interest Function........

    Code:
    /*
    Objective(s) -
    -    This code introduces the concept of User Defined Functions with a basic Compound
        Interest Calculation code
    
    Last Modification -
    -    Altered on 09-11-2009
    
    Dependencies -
    -    Supporting files 'Simple Interest.txt' and 'Exponential.txt'
    */
    
    [Report: Compound Interest Calculator]
    
        Use        : Simple Interest Calculator
        Local    : Form    : Interest Calc        : Local        : Field    : Form SubTitle    : Info    : "Compound Interest Calculator"
        Local    : Line    : Interest Result    : Local        : Field    : Medium Prompt    : Info    : "Compound Interest Amount :"
        Local    : Field    : Interest Result    : Set As    : $$CIExpCalc:#InterestPrincipal:#InterestRate:#InterestNoOfYrs
    
    ;; Function to calculate Compound Interest
    
    [Function: CIExp Calc]
    
    ;; Definition Block
    
        Parameter    : P            : Amount
        Parameter    : R            : Number
        Parameter    : T            : Number
        Returns        : Amount
    
        Variable    : Interest    : Amount
        Variable    : IntPYear    : Amount
        Variable    : Counter    : Number
    
    ;; Procedural Block
    
        01 : SET    : Counter    : 0
        02 : SET    : Interest    : 1
        03 : SET    : Interest    : (1 + (##R/100))
        05 : SET    : Interest    : $$Exponential:##Interest:##T
        06 : SET    : Interest    : (##P * ##Interest) - ##P
        07 : RETURN    : ##Interest
    
    ;; End-of-File
    
     
    Jaydeep Shah likes this.


  5. Himanshu-2002

    Himanshu-2002 Active Member


    Amit Sir has a very strong memory means seriously you remembered the path
     


  6. Amit Kamdar

    Amit Kamdar Administrator Staff Member


    LOL....no....am almost 50 yrs.

    Good memory yes...I can recollect.......but still have to search.

    I got it easy, because I follow a good system of noting down the references in all the TDLs that i make. And also I follow proper naming conventions. So even if I open a TDL after years, from the PART/Line/Field name I get to know what is what and does what............simple. :);)
     
    Jaydeep Shah likes this.


  7. Amit Kamdar

    Amit Kamdar Administrator Staff Member


    Like this.........

    Capture.PNG
     


  8. Himanshu-2002

    Himanshu-2002 Active Member


    Oo Now, I will be using the same
    Thanks For the Tip
     


Share This Page