question

PhilipWright-8672 avatar image
0 Votes"
PhilipWright-8672 asked PhilipWright-8672 commented

SB saying that it didnt expect a variable I had set earlier in code ????

Hi,

I hope someone can point me in the right direction. I want to record the highest number in the variable "high"

I'm getting this error:

"I found 'high' when I was not expecting it", for line 76 which reads : If number>high Then high=number

Variables high and number set earlier in programme

Any ideas?

Section of code where error seems to be:

number1=textwindow.ReadNumber()
evens=0
odds=0
count=0
high=0
number=number1

While number<>"1"
'count steps
count=count+1

'Establish whether number entered is odd or even
rem= Math.Remainder (number,2)

If (rem = 0) Then
TextWindow.ForegroundColor="Yellow"
TextWindow.Write( number + " is even, so divide by 2 ")
evens=evens+1
number = number/2
TextWindow.CursorLeft=40
TextWindow.WriteLine("result = " + number)
TextWindow.ForegroundColor="White"

Else
TextWindow.ForegroundColor="White"

TextWindow.Write( number + " is odd, so x 3 and + 1 ")
odds=odds+1
number = number*3
number = number+1

If number>high Then high=number

EndIf

TextWindow.CursorLeft=40
TextWindow.WriteLine("result = " + number)
Program.Delay(300)
EndIf
EndWhile

small-basic
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

JanWieldraaijer-1495 avatar image
0 Votes"
JanWieldraaijer-1495 answered PhilipWright-8672 commented

The error is in the line:`

 If number>high Then high=number

The statement high=number should be on its own line (no characters after the Then !)

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Ah Ha!
I knew it had to be something simple.

Thank you :-)

0 Votes 0 ·
PhilipWright-8672 avatar image
0 Votes"
PhilipWright-8672 answered

I cracked it :-)

I used the MAX function in MATH

high=Math.Max(number,high)

I wonder whether having an if-then line within another if-then was the problem??

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.