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

Philip Wright 21 Reputation points
2021-11-21T01:22:16.303+00:00

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
Small BASIC
A programming language created by Microsoft that serves a stepping stone for beginners from block-based coding languages to more complex text-based languages.
277 questions
0 comments No comments
{count} votes

Accepted answer
  1. WhTurner 1,611 Reputation points
    2021-11-21T17:29:35.29+00:00

    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 additional answer

Sort by: Most helpful
  1. Philip Wright 21 Reputation points
    2021-11-21T02:05:47.547+00:00

    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??

    0 comments No comments