0

I want to use the CRT unit in some Pascal code, just for the "clrscr" function but it's causing issues. The code compiles fine, but then some text is out of place and symbols appear where they shouldn't.

Here is the code:

program fuel(input, output);


var

 i,vnumber:integer;
 f,f2:text;
 volfuel,dist,totalfuel,totaldist:double;
 ch:char;
 s,z:string;

begin

 assign(f,'fuel.txt');
 assign(f2,'report.txt');
 {$i-}
 reset(f);
 rewrite(f2);
 {$i+}
 if ioresult<>0 then halt;

 totalfuel:=0;
 totaldist:=0;


 s:='~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~';
 writeln(s);
 writeln(f2,s);
 z:='Vehicle No.'+#9+'Fuel Consumption (MPG)';
 writeln(z);
 writeln(f2,z);
 writeln(s);
 writeln(f2,s);

 while not eof(f) do
 begin

 read(f,vnumber);
 read(f,ch);

 read(f,volfuel);
 read(f,ch);

 read(f,dist);

 readln(f);

 totalfuel:=totalfuel+volfuel;
 totaldist:=totaldist+dist;

 writeln(vnumber,#9,(dist/volfuel):15:2);
 writeln(f2,vnumber,#9,(dist/volfuel):15:2);

 end;

 writeln(s);
 writeln(f2,s);
 z:='~~~~~~~~~~~~~~~~~~~~SUMMARY~~~~~~~~~~~~~~~~~~~~~~~~';
 writeln(z);
 writeln(f2,z);
 writeln(s);
 writeln(f2,s);

 writeln('Total Gallons = ',totalfuel:10:2);
 writeln(f2,'Total Gallons = ',totalfuel:10:2);
 writeln('Mean Petrol Consumption = ',totaldist/totalfuel:10:2);
 writeln(f2,'Mean Petrol Consumption = ',totaldist/totalfuel:10:2);

 close(f);
 close(f2);
 readln;
end.

As soon as I add "uses crt;" that's when I get problems. It's not just happened with this Pascal program either, I few I have done and then wanted to add "clrscr" or some colour, I can't as when I add CRT, it causes spacing/formatting problems.

Any help would be great!

Liam
  • 93
  • 2
  • 13
  • Please name your OS/target. If *nix, then try using a decent terminal, like XTERM. – Marco van de Voort Jun 13 '14 at 11:56
  • Windows 7/Free Pascal. I will give XTERM a go, thanks. – Liam Jun 13 '14 at 13:49
  • add your compiler options (platform targets) and print screens of the "issues", "spacing/formatting problems". In current form your question is vague and not http://stackoverflow.com/help/mcve also add exactly what "terminal" you use. ConEmu? cmd.exe? – xmojmr Jun 14 '14 at 18:02

1 Answers1

0

If your OS is Windows, then it is probably the tab (#9) usage. Crt takes over I/O and might interpret them. But Crt on Windows should generally work fine. Detail your problems some more.

Marco van de Voort
  • 25,628
  • 5
  • 56
  • 89