I have been far too quiet, I'll have to change that.
Thus far, I have done the basics: fuel and distance can be input and fuel usage figures are out (in miles per gallon (UK and US), kilometers per litre and litres per 100 kilometers. And an unusual one: miles per litre - because in the UK fuel is sold by the Litre and vehicles record distance in Miles).
So, some photo's:
The 200LX:
The TP IDE:
editing the program:
Output sample:
Source code is available below for those wanting to play with it.
I wanted to be here a week ago! My next step is to be able to add multiple data points with date info. This will mean creating file I/O to save and recall data. This will enable one to keep historic data of fuel usage - probably usefull to do it even for different vehicles.
Halfway the month already so better get to it...
Source code thus far:
Program FuelCalc;
Uses Crt;
Var
Dt, {Distance}
Fl, {Fuel}
MPGUK, {miles per UK gallon}
MPGUS, {miles per US gallon}
KmPL, {kilometers per litre}
LPHKm, {litres per hundred km}
MPLT: real; {miles per litre}
DU, {Distance Units}
FU: char; {Fuel Units}
Wt: char;
Procedure GetValues(var Dist, Fuel: real; var DistU, FuelU: char);
Begin
While (DistU <> 'K') AND (DistU <> 'k') AND (DistU <> 'M') AND (DistU <> 'm') do
begin
WriteLn('Do you wish to enter distance in Kilometers (K) or Miles (M)?');
Write('Please enter K or M: ');
ReadLn(DistU);
end;
WriteLn;
While (Dist < 1) OR (Dist > 1E6) do
begin
Write('Please enter distance: ');
ReadLn(Dist);
end;
WriteLn;
While (FuelU <> 'A') AND (FuelU <> 'a') AND (FuelU <> 'B') AND (FuelU <> 'b') AND (FuelU <> 'C') AND (FuelU <> 'c') do
begin
WriteLn('Do you wish to enter fuel in (a)Litres, (b)UK Gallons or (c)US Gallons?');
Write('Please enter a, b or c: ');
ReadLn(FuelU);
end;
WriteLn;
While (Fuel < 1) OR (Fuel > 1E6) do
begin
Write('Please enter fuel used: ');
Read(Fuel);
end;
WriteLn;
End;
Procedure CalcValues(Dist, Fuel: real; DistU, FuelU: char; var mpgk, mpgs, kpl, lphk, mpl: real);
Var
M, {miles}
L, {litres}
Km, {kilometers}
Guk, {UK gallons}
Gus: real; {US gallons}
Begin
case DistU of
'K', 'k':
Begin
Km := Dist;
M := Dist / 1.6093;
End;
'M', 'm':
Begin
M := Dist;
Km := Dist * 1.6093;
End;
End;
case FuelU of
'A', 'a': begin
L := Fuel;
Guk := Fuel / 4.5461;
Gus := Fuel / 3.7854;
end;
'B', 'b': begin
L := Fuel * 4.5461;
Guk := Fuel;
Gus := Fuel * 4.5461/3.7854;
end;
'C', 'c': begin
L := Fuel * 3.7854;
Guk := Fuel * 3.7854/4.5461;
Gus := Fuel;
end;
end;
mpgk := M / Guk;
mpgs := M / Gus;
lphk := L / (Km / 100);
kpl := Km / L;
mpl := M / L;
End;
Procedure Output(mpgk, mpgs, kpl, lphk, mpl: real);
Begin
WriteLn('The Fuel Consumption is:');
WriteLn;
WriteLn('Miles per Gallon(UK) = ',mpgk:6:2);
WriteLn('Miles per Gallon(US) = ',mpgs:6:2);
WriteLn('Km per Litre = ',kpl:6:2);
WriteLn('Litres per 100 Km = ',lphk:6:2);
WriteLn('Miles per Litre = ',mpl:6:2);
WriteLn;
End;
Begin {main}
Dt := 0;
Fl := 0;
MPGUK := 0;
MPGUS := 0;
KmPL := 0;
LPHKm := 0;
MPLT := 0;
DU := ' ';
FU := ' ';
ClrScr;
GetValues(Dt, Fl, DU, FU);
CalcValues(Dt, Fl, DU, FU, MPGUK, MPGUS, KmPL, LPHKm, MPLT);
Output(MPGUK, MPGUS, KmPL, LPHKm, MPLT);
WriteLn('Press ENTER to exit... ');
ReadLn(Wt);
End.
No comments:
Post a Comment