主题:请求高手帮助
下面的代码 为何测试不能通过 请求高手帮助 谢谢!
Program ruin;
{[A+,T=3]Instruction to PasMat.}
Uses
Dos;
Type
String80=String[80];
Var
Name:String80;
Infile,Outfile:Text;
C22,NSet,NSetL,Index:LongInt;
BoundLower,BoundUpper,Cap,Capital,Del,
Probability,ProbabilityWin,ProbablityLose,
TradeWin,TradeLose:Extended;
Hour,Minute,Sec,Sec100,Year,Month,Day,
DayOfWeek:Word;
Begin
Write('Input file name:');
ReadLn(Name);
Assign(Infile,Name);
Reset(Infile);
Write('Output file name:');
ReadLn(Name);
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 / 10= NSet Div 10) then
Write(^M,'Iteration Number',
(Nset + (Index * NsetL)) :1,'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<=0) 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);
WriteLn(Outfile,'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;
WriteLn(Outfile,'Ending at',Hour:2,':',
Minute:2,':',Sec:2,'on',Month:2,
'/',Day,'/',Year)
WriteLn(Outfile);
Until Eof(Infile);
Close(Infile);
Close(Outfile);
End.
Program ruin;
{[A+,T=3]Instruction to PasMat.}
Uses
Dos;
Type
String80=String[80];
Var
Name:String80;
Infile,Outfile:Text;
C22,NSet,NSetL,Index:LongInt;
BoundLower,BoundUpper,Cap,Capital,Del,
Probability,ProbabilityWin,ProbablityLose,
TradeWin,TradeLose:Extended;
Hour,Minute,Sec,Sec100,Year,Month,Day,
DayOfWeek:Word;
Begin
Write('Input file name:');
ReadLn(Name);
Assign(Infile,Name);
Reset(Infile);
Write('Output file name:');
ReadLn(Name);
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 / 10= NSet Div 10) then
Write(^M,'Iteration Number',
(Nset + (Index * NsetL)) :1,'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<=0) 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);
WriteLn(Outfile,'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;
WriteLn(Outfile,'Ending at',Hour:2,':',
Minute:2,':',Sec:2,'on',Month:2,
'/',Day,'/',Year)
WriteLn(Outfile);
Until Eof(Infile);
Close(Infile);
Close(Outfile);
End.