Hello again. A few days ago I asked for help with a pascal program capable of converting numbers from X base to base 10. I'm sorry if I didn't reply, I got a lot of help and I appreciate it. I was able to pull it off the day after asking for help.
I turned in my program but was told that it was incorrect due to a "possible mistreatment of end of line, a character present in Unix". Windows is my main OS so I guess I can't exactly fix this problem without installing Linux, something I'd rather not do.
Can anyone tell me if this problem is present in my code? And if so, how can I fix it?
Just in case, I'm 100% sure the program is working as intended. We were given a Perl file which gives the program 15 inputs and analyzes the output with an expected output. In my case, all 15 inputs were handled correctly by my program.
program test;
const
maxlargo = 7;
dot = '.';
sep = ':';
sec = '$';
var
c:char;
x,i,b,d,base:integer;
res:longint;
begin
i := -1;
(*Reads the input and locks it to be shorter or equal to 7 numbers (maxlargo), and to close the program if the input is '$'.*)
read(c);
while (c <> sec) and (i <= maxlargo) do
begin
b := 0;
base := 0;
res := 0;
x := 0;
d := 0;
i := -1;
(*Reads until colon to determine base.*)
while (c <> sep) do
begin
d := ord(c) - ord('0');
b := b+1;
(*Checks if the base has one or two numbers, and reacts accordingly.*)
if b = 2 then
base := base*10 + d
else
base := d;
(*Reads the next input for the base.*)
read(c);
end;
(*Reads until period to determine number to convert.*)
while (c <> dot) and (i <= maxlargo) do
begin
i:=i + 1;
(*Locks said number to a max amount of characters. If the input is longer than 7, the program returns an ERROR and doesn't convert it at all.*)
if i > maxlargo then
writeln('ERROR')
else
begin
case c of
'0'..'9' : x := ord(c) - ord('0');
'A'..'F' : x := ord(c) - ord('A') + 10;
end;
res := (x + (res*base));
(*Reads the next input for the number.*)
read(c);
end;
end;
if i <= maxlargo then
writeln(res);
(*Restarts the program.*)
read(c); read(c); read(c);
end;
end.