Ok, so I'm sorry if this is a silly question, but I've checked the code over and over again, and I simply can't figure out why it wont compile.
Here's the error:
Quote:
assignment4Equation_Solver.p: In procedure `Temptotal':
assignment4Equation_Solver.p:4: invalid use of void expression
assignment4Equation_Solver.p:5: invalid use of void expression
assignment4Equation_Solver.p: In procedure `Parsenum':
assignment4Equation_Solver.p:8: parse error before `Read'
|
And here is the code:
Code:
Program assignment4Equation_Solver(input,output);
Procedure tempTotal(var total, numtemptotal);
begin
numtempTotal := total; {store the total remotely}
total := 0; {reset the total}
end;
Procedure parseNum(var total);
read(ch);
while (ch in [0,9]) then
total := total*10+(ord(ch)- ord('10'));
until (not ch in['0','9'])
if (ch = '.') then
{read another integer}
{combine the +ve numbers}
begin
read(ch);
while (ch in [0,9]) then
total := total+(ord(ch) / ord('10'));
until (not ch in['0','9'])
end;
Procedure chkNextInput; {checks to see if next input is a number, and not another operator}
if (not ch in [0,9]) then
begin
writeln('Bad Input')
badInput := true;
Break;
end;
CONST
VAR
total,
numtempTotal: real;
badInput: boolean;
begin
{*
input
*}
badInput := false;
write('Enter the Equation: ');
readln(equation);
{*
Parse the input, check for errors and calculate total.
*}
numtempTotal := 0;
total := 0;
while not eoln(equation) do
begin
if (badInput) then
begin
Break;
end;
readNum;
read(ch);
case ch of
'+';
tempTotal(total);
parseNum;
total := total + numtempTotal;
chkNextInput;
case ch of
'-'
tempTotal(total);
parseNum;
total := total - numtempTotal;
chkNextInput;
case ch of
'*'
tempTotal(total);
parseNum;
total := total * numtempTotal;
chkNextInput;
case ch of
'/'
tempTotal(total);
parseNum;
total := total / numtempTotal;
chkNextInput;
if (eoln(equation)) then
writeln('The answer to the equation is: ', total);
else
if (badInput) then
begin
Break;
end;
end;
end.
I'm a complete newb to pascal, but it looks fine to me..
-thanks in advance