OK, I cleaned it up as far as I could.
I commented out code that I could not make sense of at all (what the hell is this supposed to mean: "If (NSet / = NSet Div) then" ???).
Program ruin;
{$mode objfpc}
Uses
Dos, SysUtils;
Type
String80 = String [80];
Var
Name: String80;
Infile, Outfile: Text;
C22, NSet, NSetL, Index: LongInt;
BoundLower, BoundUpper, Cap, Capital, Del,
Probability, ProbabilityWin, ProbabilityLose,
TradeWin, TradeLose, C1: Extended;
Hour, Minute, Sec, Sec100, Year, Month, Day,
DayOfWeek: Word;
Begin
//Write(' Input file name: ');
//ReadLN(Name);
Name := 'sample_in.txt';
Assign(Infile, Name);
Reset(Infile);
//Write(' Output file name: ');
//ReadLN(Name);
Name := 'sample_out.txt';
Assign(Outfile, Name);
Rewrite(Outfile);
Randomize;
WriteLn;
Repeat
GetTime(Hour, Minute, Sec, Sec100);
GetDate(Year, Month, Day, DayOfWeek);
ReadLn(Infile, Name);
WriteLn(Outfile, Name);
Readln(Infile, Capital, TradeWin, TradeLose, NSetL);
WriteLn(Outfile);
WriteLn(Outfile, 'Probability of Win Probability of Ruin');
Del := 0.05;
ProbabilityWin := 0.00;
BoundLower := 0.0;
BoundUpper := 100 * Capital;
For Index := 0 to 17 do
Begin
ProbabilityWin := ProbabilityWin + Del;
NSet := 0;
C22 := 0;
Repeat
Cap := Capital;
Inc(NSet);
//If (NSet / = NSet Div) then ?????
Write (^M, 'Iteration Number ',(NSet + (Index * NSetL)), ' of ', (18 * NSetL): 1);
Repeat
Probability := Random;
{random between 0 and 1}
If (Probability <= ProbabilityWin) then
Cap := Cap + TradeWin
else
Begin
Cap := Cap + TradeLose;
If (Cap <= C1) then
Inc(C22)
End
Until ((Cap >= BoundUpper) or (Cap <= BoundLOwer))
Until (NSet >= NSetL);
ProbabilityLose := C22 / NSet;
WriteLN(Outfile, ' ',
ProbabilityWin: 10: 8, ' ', ProbabilityLose: 10: 8)
End;
WriteLn;
WriteLn;
WriteLn(Outfile);
WriteLn('Starting at ', Hour: 2, ':', Minute: 2, ':', Sec: 2, ' on ', Month: 2, '/', Day, '/', Year);
GetTime(Hour, Minute, Sec, Sec100);
GetDate(Year, Month, Day, DayOfWeek);
WriteLn('Ending at ', Hour: 2, ':', Minute: 2, ':', Sec: 2, ' on ', Month: 2, '/', Day, '/', Year);
WriteLn(Outfile)
Until Eof(Infile);
Close(Infile);
Close(Outfile);
End.
And here my input file;
Name
1000.0 500.0 250.0 125
Output on console:
C:\Users\Bart\LazarusProjecten\ConsoleProjecten\bugs\ruin>ruin
Iteration Number 2250 of 2250
Starting at 11:52:29 on 7/14/2015
Ending at 11:52:29 on 7/14/2015
Text in outputfile:
Name
Probability of Win Probability of Ruin
0.05000000 0.00000000
0.10000000 0.00000000
0.15000000 0.00000000
0.20000000 0.00000000
0.25000000 0.00000000
0.30000000 0.00000000
0.35000000 0.00000000
0.40000000 0.00000000
0.45000000 0.00000000
0.50000000 0.00000000
0.55000000 0.00000000
0.60000000 0.00000000
0.65000000 0.00000000
0.70000000 0.00000000
0.75000000 0.00000000
0.80000000 0.00000000
0.85000000 0.00000000
0.90000000 0.00000000
To me it is totally unclear what it means, but have fun with it...
Bart