Recent

Author Topic: [SOLVED]Why isn't my array working?  (Read 2957 times)

molly

  • Hero Member
  • *****
  • Posts: 2345
Re: Why isn't my array working?
« Reply #15 on: December 21, 2017, 07:22:17 pm »
P.S.
Molly, maybe you posted the same answer - I just did not understand it...
I simply used less words to express the problem. "Use code-tags" should be obvious for seasoned posters and a hint for newbies.

@svy249:
Also here i'm unable to 'see' the problem. i used 1 and 2 as well as 10 and 20 for input which resulted int he answer 3 and 2. Not one.

Handoko

  • Hero Member
  • *****
  • Posts: 3158
  • My goal: build my own game engine using Lazarus
Re: Why isn't my array working?
« Reply #16 on: December 21, 2017, 07:23:34 pm »
Thanks for clearing the misunderstanding.

Now, time for serious. Not sure what TS want to do but I found this is bad:
Code: Pascal  [Select]
  1.     if h[i] > f then

The variable "f" hasn't been initialized. Also the variable "s".
« Last Edit: December 21, 2017, 07:25:35 pm by Handoko »

molly

  • Hero Member
  • *****
  • Posts: 2345
Re: Why isn't my array working?
« Reply #17 on: December 21, 2017, 07:25:48 pm »
That is indeed a hint from compiler that shouldn't be ignored Handoko.

Handoko

  • Hero Member
  • *****
  • Posts: 3158
  • My goal: build my own game engine using Lazarus
Re: [SOLVED]Why isn't my array working?
« Reply #18 on: December 21, 2017, 07:29:20 pm »
Tested on Lazarus, global integer variables that are not initialized have value = 0.
So that if-then always returns false true.
« Last Edit: December 21, 2017, 07:34:52 pm by Handoko »

svy249

  • Newbie
  • Posts: 4
Re: Why isn't my array working?
« Reply #19 on: December 21, 2017, 07:32:01 pm »
Thanks.  :D  Random just messed with me and I got the same result over and over again.

molly

  • Hero Member
  • *****
  • Posts: 2345
Re: [SOLVED]Why isn't my array working?
« Reply #20 on: December 21, 2017, 07:40:03 pm »
Tested on Lazarus, global integer variables that are not initialized have value = 0.
So that if-then always returns false true.
Sorry to be such a pita but a small correction (in basic you are correct):
Code: [Select]
  for i:=1 to 5
    do if h[i] > f then
    begin
      f:=h[i];
      s:=i ;
    end;
So on first iteration that statement holds while it doesn't for the follow up iterations (ofc depending on what values are stored inside h array).

@svy249:
using random(ize) can indeed sometimes mess with your expectations... in case you are unsure then simply write out the values so that you are able to see them.