Pascal

Moderators: None (Apply to moderate this forum)
Number of threads: 4095
Number of posts: 14004

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

Report
Help on Pascal Program: Balance Posted by rodneybunkley on 7 Apr 2010 at 1:14 PM
Hi, I'm doing a program on Balance, and it's suppose to look something like this.

Year
Balance Rate(%) 1 2 3 4 5 6 7 8 9 10
100 10 110 121 133 146 161 177 ... ...
200 10 ... ... ... ...
300 10 ... ... ..
400 10 .... ... ..
500 10 ... ... ...

I did the program but it keeps coming out wrong. Can someone please help me fix my program or tell me what am i missing?

PROGRAM BALANCE(INPUT,OUTPUT, DATA6, OUT6);

VAR DATA6, OUT6: TEXT;
BALANCE, RATE: INTEGER;
VCOUNT, LCOUNT: INTEGER;



(**************************************************)
PROCEDURE ProduceLine(VAR VCOUNT, BALANCE, RATE: INTEGER);

BEGIN
WRITE(BALANCE:6);
WRITE(RATE:6);
VCOUNT:= 0;
WHILE VCOUNT <= 10 DO
BEGIN
BALANCE:= BALANCE + BALANCE * RATE;
WRITE(BALANCE);
VCOUNT:= VCOUNT + 1

END;
END;


(*************************************************)
PROCEDURE ProduceTable(VAR LCOUNT, VCOUNT: INTEGER;
BALANCE, RATE: INTEGER);
BEGIN
WRITELN('YEAR');
WRITELN('BALANCE RATE(%)');
LCOUNT:= 0;
WHILE LCOUNT <= 5 DO
BEGIN
ProduceLine(VCOUNT, BALANCE, RATE);
BALANCE:= BALANCE + 100;
LCOUNT:= LCOUNT + 1;
WRITELN
END;
END;
(************************************************)

BEGIN
RESET(DATA6);
REWRITE(OUT6);
WRITE('ENTER BALANCE AND RATE:');
READ(BALANCE, RATE);
WHILE NOT EOF DO
BEGIN
ProduceTable(LCOUNT, VCOUNT, BALANCE, RATE);
WRITELN;
IF EOLN
THEN READLN
END;


END.
Report
Re: Help on Pascal Program: Balance Posted by Actor on 11 Apr 2010 at 7:07 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.

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.




 

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.