Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There is a number of problems. <strong>First</strong>, when you write</p> <pre><code>for K:=0 to Count-1 do Temperatures[K] := lstTemp.Items[K]; if (Temperatures[K] &gt; Max) then Max := Temperatures[K]; if (Temperatures[K] &lt; Min) then Min := Temperatures[K]; </code></pre> <p>you actually do</p> <pre><code>for K:=0 to Count-1 do Temperatures[K] := lstTemp.Items[K]; if (Temperatures[K] &gt; Max) then Max := Temperatures[K]; if (Temperatures[K] &lt; Min) then Min := Temperatures[K]; </code></pre> <p>which is nonsense. You want <em>all</em> these lines to be part of the <code>for</code> loop:</p> <pre><code>for K:=0 to Count-1 do begin Temperatures[K] := lstTemp.Items[K]; if (Temperatures[K] &gt; Max) then Max := Temperatures[K]; if (Temperatures[K] &lt; Min) then Min := Temperatures[K]; end; </code></pre> <p><strong>Second</strong>, in order for this algorithm to work, the initial value of <code>Min</code> (<code>Max</code>) needs to be larger (smaller) than the values in the list. This might work for <code>Max := 0</code>, but probably not for <code>Min := 0</code>. You need to set <code>Min</code> to a very large value before you run the loop, obviously. The best value you can use is the highest-possible signed 32-bit integer value, that is, 2^31 - 1, which is the value of the <code>MaxInt</code> constant.</p> <p><strong>Third</strong>,</p> <pre><code>Temperatures[K] := lstTemp.Items[K]; </code></pre> <p>is probably wrong. <code>Temperatures</code> is an array of <strong>integers</strong>, while <code>lstTemp.Items[K]</code> is a <strong>string</strong> (at least according to <code>StrToInt(lstTemp.Items[i])</code>), so you need</p> <pre><code>Temperatures[K] := StrToInt(lstTemp.Items[K]); </code></pre> <p><strong>Fourth</strong>, you declare <code>Average</code> as an <code>integer</code>, but it needs to be a floating-point number (obviously), like <code>real</code> or <code>double</code>.</p> <p><strong>Fifth</strong>,</p> <pre><code>edtAvg.Text:=IntToStr(Average); //Display Average edtAvg.Text:=IntToStr(Min); //Display Minimum Temp. edtAvg.Text:=IntToStr(Max); //Display Maximum Temp. </code></pre> <p>is not techncally incorrect, but will most likely not do what you want.</p> <p><strong>Sixth</strong>, although not an error, there is no need for you to initialise <code>Count</code> and <code>Average</code> to <code>0</code>. Finally, you only need a single <code>for</code> loop.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload