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
[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]
[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]