making a calculator using records, pointers and links. - Programmers Heaven

Howdy, Stranger!

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

Categories

making a calculator using records, pointers and links.

pascal_llpascal_ll Posts: 1Member
hey, im trying to work with records and pointers. i have to make a calculator that will calculator any question that i input. the trouble im having is that i dont' know how to find doing the calculation part. i have the equation down, but now im stuck on how to start the calculation. thanks for the help. bye




program pointers6a (input, output);

type
onepoint = ^one;
one = record
numb : integer; {the number in the equation}
oper : char; {the operator in the equation}
next : onepoint; {move to the next node}
end;

const space = ' ';

var
p1, {first numbers for the equation}
p2, {second numbers for the equation}
start, {beginning of the node}
tail {end of node}
: onepoint;
temp : integer;
num {true or false}
: boolean;


procedure printlist (p1 : onepoint);
{*******************************************************************
***********
purpose:to display the original equation on the screen for user to v
iew.
input:the equation in which the user types in.
output:the equation of what the user has typed in.
********************************************************************
**********}
begin
while (p1 <> tail) do
begin
if(p1^.numb > 0) and (p1^.numb < 1000) then
write (p1^.numb);
if(p1^.oper in['+', '-', '*', '/']) then
write(p1^.oper);
p1:=p1^.next;
end;
end; { printlist }


begin {main program}
num := true;
new(start);
read(temp);
start^.numb := temp;
start^.oper:= space;
start^.next:=nil;
tail:= start; {set tail to the beginning}
p1:= start; {set p1 to the beginning}
p2:= start; {set p2 to the beginning}

while (tail^.oper <> '=') do
begin
new(p1);
p1^.next := nil;
if (num) then
begin
read(p1^.oper);
p1^.numb:=0;
num:= false;
end
else
begin
read(p1^.numb);
p1^.oper:=space;
num:=true;
end;
p2^.next:= p1;
p2 := p1;
tail:=p1;
end;
printlist(start); {printing out the equation from printlist procedure}
evaluate(p1);
end.

Sign In or Register to comment.