Pascal

Moderators: None (Apply to moderate this forum)
Number of threads: 4106
Number of posts: 14016

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Re: Help on Pascal Program: Balance Posted by Actor on 11 Apr 2010 at 7:11 PM
Your program seems to be a savings accumulation program. Here's my solution.
program balanceprog ; { my compiler, TP7.0, does not allow
                      the use of the word balance
                      as both a program name and as a variable
                      so I've changed the name of the program. }

        procedure producetable (balance, rate : real) ;
            {
                balance and rate are the only variables
                that need to be passed to the procedure.  The only
                other variable, lcount, is only used locally
                and is declared as such.  In any case TP requires that
                index counters be declared locally.
            }

            procedure produceline (balance, rate : real) ;
                {
                    produceline is invoked only  by
                    producetable so it is appropriate to nest
                    the latter within the former.
                }
    
            var
                vcount : integer ; { must be local }
    
            begin
                write(balance:7:0) ;
                write(rate:8:0) ;
    
                for vcount := 1 to 10 do begin
                    balance:= balance + (balance * rate / 100.0) ;
                    write(balance:6:0)
                end
            end ;
        
        var
            lcount : integer ;

        begin
            writeln ('year') ;
            write   ('balance rate(%)') ;
            for lcount := 1 to 10 do
                write (lcount:6) ;
            writeln ;

            for lcount := 1 to 5 do begin
                produceline (balance, rate) ;
                balance := balance + 100.0 ;
                writeln
            end
        end ;

var
    balance, rate   :   real ;  { real fits these variables
                                       better than integer }

begin
    writeln ;
    write ('enter balance and rate:') ;
    read (balance, rate) ;

    producetable (balance, rate) ;
    writeln
end.

Thread Tree
rodneybunkley Help on Pascal Program: Balance on 7 Apr 2010 at 1:14 PM
Actor Re: Help on Pascal Program: Balance on 11 Apr 2010 at 7:07 PM
Actor Re: Help on Pascal Program: Balance on 11 Apr 2010 at 7:11 PM



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.