Results 1 to 3 of 3

Thread: Math problem

  1. #1
    Join Date
    Oct 2007
    Location
    Denmark
    Posts
    409
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Math problem

    I'm as some of you know working on a GE Merchanter and this is my GetAdvice function:
    SCAR Code:
    procedure GetAdvice;
    var
      Max, i, Item: Integer;
      Per: Extended;
      INI, Write: String;
      A: TAuc;
    begin
      Max := ItemsInDB;
      Writeln('We suggest you buy these items:');
      for i := 0 to Max do
      begin
        INI := ReadINI('Items', IntToStr(i), Path);
        ConvertINI(INI, A.Name, A.Min, A.Mark, A.Max, A.ID);
        Per := (A.Mark - A.Min) / (A.Max - A.Min) * 100.0;
        if (Per < Percenter) then
        begin
          Inc(Item);
          Write := 'Item: ' + A.Name + ' is at ' + IntToStr(A.Mark) + ' gp ( ' + FloatToStr(Per) + '% of max) and has ' +
                   'been seen at a max of ' + IntToStr(A.Max);
          Writeln(Write);
        end;
      end;
    end;

    However, this always outputs 0: Per := (A.Mark - A.Min) / (A.Max - A.Min) * 100.0;

    A.Mark, A.Min and A.Max all holds a number so I can't figure out why it outputs a zero.

    Any help will be appreciated

  2. #2
    Join Date
    Feb 2007
    Location
    South East England
    Posts
    2,906
    Mentioned
    2 Post(s)
    Quoted
    8 Post(s)

    Default

    It might be that A.Mark, A.Min and A.Max arent being assigned values, so they are always 0 in the first place, and 0-0/0-0 = 0/0 = Math Problem.
    Jus' Lurkin'

  3. #3
    Join Date
    Oct 2007
    Location
    Denmark
    Posts
    409
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Figured it out.
    The problem was that the minimum price was equal to the market price.
    Ended up with this if anyone is interested:
    SCAR Code:
    procedure GetAdvice;
    var
      Max, i, Item: Integer;
      C: array [0..1] of Extended;
      Per: Extended;
      INI, Write: String;
      A: TAuc;
    begin
      Max := ItemsInDB;
      Writeln('We suggest you buy these items:');
      for i := 0 to Max do
      begin
        INI := ReadINI('Items', IntToStr(i), Path);
        ConvertINI(INI, A.Name, A.Min, A.Mark, A.Max, A.ID);
        C[0] := A.Mark - A.Min;
        C[1] := A.Max - A.Min;
        if (C[0] = 0.0) then
          C[0] := C[0] + 1.0;
        if (C[1] = 0.0) then
          C[1] := C[1] + 1.0;
        Per := Round(C[0] / C[1] * 100);
        if (Per < Percenter) then
        begin
          Inc(Item);
          Write := 'Item: ' + A.Name + ' is at ' + IntToStr(A.Mark) + ' gp ( ' + FloatToStr(Per) + '% of max) and has ' +
                   'been seen at a max of ' + IntToStr(A.Max);
          Writeln(Write);
        end;
      end;
    end;

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •