Recent

Author Topic: Compile error  (Read 7280 times)

olobay

  • Newbie
  • Posts: 2
Compile error
« on: July 14, 2015, 05:20:46 am »
Hi First time using Pascal. I found a code online and tried to copy it but I get a compile error: Unexpected end of file. What is wrong with attached code? Thanks.

Code: [Select]
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, ProbablityWin, ProbabilityLose,
                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;
        Begin
        ProbabilityWin := ProbabilityWin + Del;
        NSet :=;
        C :=;
        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, '      ', Probability Lose: 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, '/', Month: 2, '/',
                 Day, '/', Year);
                 WriteLn(Outfile)
                 Until Eof(Infile);
                 Close(Infile);
                 Close(Outfile);
                 End




BitBangerUSA

  • Full Member
  • ***
  • Posts: 183
Re: Compile error
« Reply #1 on: July 14, 2015, 05:42:39 am »
i see several things, ranging from 'typos' to horrible formatting to bad design.

you might want to search the web for a site that has much better coding examples.

others on this site - Lazarus Forum - may be more inclined than i to clean up such bad code, so check every once in a while.

if you don't mind - where did you find this code?

Lazarus Ver 2.2.6 FPC Ver 3.2.2
Windows 10 Pro 64-bit

kamischi

  • Full Member
  • ***
  • Posts: 177
Re: Compile error
« Reply #2 on: July 14, 2015, 06:58:26 am »
The final "." after the last "End" is missing. This may be the reason for the error message. The formatting of this code is a real pain. For a better formatting, maybe try the utility "ptop"or lazarus or any other editor with Pascal formatting. Getting this piece of code into a nice shape is quite a task, but you will probably learn a lot.

MiSchi
fpc 2.6.4, lazarus 1.4.0, Mac OS X, fink

rvk

  • Hero Member
  • *****
  • Posts: 6989
Re: Compile error
« Reply #3 on: July 14, 2015, 10:12:44 am »
Well, I began cleaning up the code but after the 10th error I gave up. You have missing variables ( like ProbabilityWin, C and C1 ) and missing assignments ( like NSet :=; and C :=; )

And for instance that missing ProbabilityWin... you have a variable ProbablityWin which isn't the same (spelled wrong).

You're missing some ; on critical places.

You say the code is taken from somewhere online but it would never have run. If you want to continue with this code my suggestion is running it and fixing every error you encounter but I think you're better off finding some other code which actually compiles.

Bart

  • Hero Member
  • *****
  • Posts: 5712
    • Bart en Mariska's Webstek
Re: Compile error
« Reply #4 on: July 14, 2015, 10:50:30 am »
Why did you start with this program?
Is it supposed to do something usefull to you, and if so, what exactly is it (are you) trying to achieve?
Did it come with an example input file?

Did you notice that almost the entire text of this program is in fact a comment (it has an opening "{", but not a closing "}")?
There should be no colon (":") after "Program ruin", so even in the first line they (?) manged to screw it up, and that line is the only line (as far as the compiler is concerned) that contains any code...

The name of the program (ruin) says it all  >:D

Bart

Leledumbo

  • Hero Member
  • *****
  • Posts: 8836
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Compile error
« Reply #5 on: July 14, 2015, 11:39:43 am »
This is what happens when learner starts from copy-paste-ing codes. It won't work, dude. Won't work.

Bart

  • Hero Member
  • *****
  • Posts: 5712
    • Bart en Mariska's Webstek
Re: Compile error
« Reply #6 on: July 14, 2015, 11:58:40 am »
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" ???).

Code: [Select]
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;
Code: [Select]
Name
1000.0 500.0 250.0 125

Output on console:
Code: [Select]
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:
Code: [Select]
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
« Last Edit: July 14, 2015, 12:09:38 pm by Bart »

olobay

  • Newbie
  • Posts: 2
Re: Compile error
« Reply #7 on: July 14, 2015, 02:54:24 pm »
Thanks for all the help everyone. Is there a way to thank each post in this forum?

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Compile error
« Reply #8 on: July 14, 2015, 03:25:01 pm »
You just did thank everyone.

 

TinyPortal © 2005-2018