Re: Mph to Mps - this is what I have so far

Posted by WAllison on March 13, 2003

In Reply to: Mph to Mps - this is what I have so far posted by MIKE on March 13, 2003

: program task2;

: {$APPTYPE CONSOLE}

: uses
: SysUtils;
: const
: MilesToMetres = 1606.344;
: var
: Speed : integer ;
: mph, // miles per hour ;
: mps : real ; // metres per second ;
: begin
: { TODO -oUser -cConsole Main : Insert code here }
: write ( 'Key in Speed : ') ;
: readln (speed, mph);
: writeln (' This speed in mps is', speed, mps );
: readln;
: end.

This might help m8
const
AMile = 1606.344;
var
Mph, Mps: real;
begin
Mps := AMile * Mph /60 /60;
end;

let me know if it aint right - i couldn't find a comparison of any type for the results. Using a calculator everything seemed ok...

heres some source:

unit Main;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Menus, ComCtrls, StdCtrls;
type
  TMainForm = class(TForm)
    MainStatusBar: TStatusBar;
    MainMenu1: TMainMenu;
    Exit1: TMenuItem;
    Exit2: TMenuItem;
    MphEdit: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    MpsEdit: TEdit;
    ConvertButton: TButton;
    KmphEdit: TEdit;
    Label3: TLabel;
    procedure Exit2Click(Sender: TObject);
    procedure ConvertButtonClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    function MilesPerHourToMetresPerSecond(Mph: Real): Real;
  end;
var
  MainForm: TMainForm;
const
  AMile = 1606.344;
implementation
{$R *.dfm}
function TMainForm.MilesPerHourToMetresPerSecond(Mph: Real): Real;
begin
  KmphEdit.Text := FloatToStr(AMile*Mph);
  Result := AMile * Mph /60 /60;
end;
procedure TMainForm.Exit2Click(Sender: TObject);
begin
  close;
end;
procedure TMainForm.ConvertButtonClick(Sender: TObject);
begin
  If (MphEdit.Text <> '') or (MphEdit.Text <> null) then
    MpsEdit.Text := MilesPerHourToMetresPerSeond(StrToFloat(MphEdit.Text)));
end;
end. 

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