Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Help on Pascal Program: Balance

rodneybunkleyrodneybunkley Posts: 5Member
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.

Comments

  • ActorActor Posts: 438Member
    Your program seems to be a savings accumulation program. Here's my solution.
    [code]
    program balanceprog ; [red]{ my compiler, TP7.0, does not allow
    the use of the word [b]balance[/b]
    as both a program name and as a variable
    so I've changed the name of the program. }[/red]

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

    procedure produceline (balance, rate : real) ;
    [red]{
    [b]produceline[/b] is invoked only by
    [b]producetable[/b] so it is appropriate to nest
    the latter within the former.
    }[/red]

    var
    vcount : integer ; [red]{ must be local }[/red]

    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 ; [red]{ real fits these variables
    better than integer }[/red]

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

    producetable (balance, rate) ;
    writeln
    end.
    [/code]
  • ActorActor Posts: 438Member
    Your program seems to be a savings accumulation program. Here's my solution.
    [code]
    program balanceprog ; [red]{ my compiler, TP7.0, does not allow
    the use of the word [b]balance[/b]
    as both a program name and as a variable
    so I've changed the name of the program. }[/red]

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

    procedure produceline (balance, rate : real) ;
    [red]{
    [b]produceline[/b] is invoked only by
    [b]producetable[/b] so it is appropriate to nest
    the latter within the former.
    }[/red]

    var
    vcount : integer ; [red]{ must be local }[/red]

    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 ; [red]{ real fits these variables
    better than integer }[/red]

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

    producetable (balance, rate) ;
    writeln
    end.
    [/code]
Sign In or Register to comment.