I am working on Functions for my class and I am testing to make sure the input values are valid. As a test I am reading in the first line of data which is 'C 10 10 10 20'. I set the variable 'Check' to 0; then if I send those values through a function and if the values of those 4 numbers are higher or lower it should change the value of Check from 0 to 1.
The end result should be 0 before and after the function but it is returning 1.
result from the file out
The values are bunched together for now since I have not put a separator between them so instead of C 10 10 10 20 it is C10101020.
Thanks,
-Lars
The end result should be 0 before and after the function but it is returning 1.
Code:
program chap9(infile, outfile);
var
ch : char;
check,A,B,C,D : integer;
infile, outfile : text;
FUNCTION INRANGE(A,B,C,D:integer):integer;
begin
if ((A < 10) OR (A > 20))
then INRANGE := 1;
if ((B < 10) OR (B > 20))
then INRANGE := 1;
if ((C < 10) OR (C > 20))
then INRANGE := 1;
if ((D < 10) OR (D > 20))
then INRANGE := 1;
end;
begin
reset(infile);
rewrite(outfile);
check := 0;
WHILE NOT EOLN(infile) do
begin
writeln(outfile,'the check before: ',check); (* displays what check is*)
READ(infile, ch, A,B,C,D);
writeln(outfile,'The Values read: ',ch , A , B , C , D);
check := INRANGE(A,B,C,D);
writeln(outfile, 'the check after: ', check);
end;
readln(infile);
end.
result from the file out
the check before: 0
The Values read: C10101020
the check after: 1
The values are bunched together for now since I have not put a separator between them so instead of C 10 10 10 20 it is C10101020.
Thanks,
-Lars