Re: Help with Delphi console program

Posted by khan on April 12, 2003

In Reply to: I need help with the CODE of my console program. posted by John Heathor on April 01, 2003

I couldn't format the real variable, then this may seem a bit long. In fact, this could be done shorter from the below but may give you an idea (and solves the problem in a long way)

program Project1;
  
{$APPTYPE CONSOLE}
  
uses
  SysUtils;
var 
  dollars, cents:real;
  dolst,centst:string;

procedure getAmounts(money : real);
begin
  dolst:=floattostr(trunc(money));
  centst:=floattostr(abs(round((money-trunc(money))*100)));
end;
  
begin
  getAmounts( -123.45 );
  writeln;
  writeln (dolst,'dollars', ' and ', centst, ' cents.' );
  getAmounts( 67.1 );
  writeln( '$', dolst,'dollars', ' and ', centst, ' cents.' );
  getAmounts( 345.0 );
  writeln( '$', dolst,'dollars', ' and ', centst, ' cents.' );
  readln;
end. 

[ DelphiLand Discussion Forum ]
Compiling Console Applications
Learn Pascal with simple Delphi Console Applications