I'm trying to make a FizzBuzz program.
If you don't know what FizzBuzz is, you can read about it here:
http://codingbat.com/doc/practice/fizzbuzz-code.html

I'm getting syntax errors. I'm a beginner, could you help me fix the problems?


Code:

0->L
While L<=100
L+1->L
L/3->A
L/5->B
If not(fPart(A
Then
Goto 1
Else
:If not(fPart(A
:Then
:Disp "Fizz"
:Else
::If not(fPart(B
::Then
::Disp "Buzz"
::Else
::Disp L
::End
:End
End
End
Lbl 1
If not(fPart(B
Then
Disp "FizzBuzz"
End


I also tried:

Code:

If not(fPart(A and not(fPart(B

but I'm not sure if my syntax is right.
When pressing 2:Goto (if that is an option), what does the cursor highlight in the program? Also,
Code:
If not(fPart(A and not(fPart(B
will definitely cause a syntax error. It should be
Code:
If not(fPart(A)) and not(fPart(B
Michael2_3B wrote:
When pressing 2:Goto (if that is an option), what does the cursor highlight in the program? Also,
Code:
If not(fPart(A and not(fPart(B
will definitely cause a syntax error. It should be
Code:
If not(fPart(A)) and not(fPart(B


I'm really not sure what you meant by that... I'm a total beginner to this.

My first block of code doesn't include testing for both at the same time, but it still has errors.
You said you were having syntax errors. When the syntax err pops up, it says:

Code:

ERR:SYNTAX
1:Quit
2:Goto

I'm not sure if it has the goto option or not, but if it does, what does the cursor highlight in your program after pressing Goto?
Michael2_3B wrote:
You said you were having syntax errors. When the syntax err pops up, it says:

Code:

ERR:SYNTAX
1:Quit
2:Goto

I'm not sure if it has the goto option or not, but if it does, what does the cursor highlight in your program after pressing Goto?


It highlights:

Code:

:If not(fPart(A
:Then
:Goto 1
:Else
::If not(fPart(A
::Then <<----This bit

Hmm. I hardly ever use the Else function, but I think maybe you can't have an If...Then block under Else. Not even sure if you can have an If statement. The else function should only be used if the previous if statement equated to false, and should not need an if statement under it.

Also, your code you just posted is pointless. You are basically saying, "if not(fPart(A)) then do this, but if that statement equates to false (if fPart(A)), then if not(fPart(A)), do something else. Instead, why not just do:

Code:

:If not(fPart(A
:Then
:((your other code that you put after else))
:Goto 1

Also be careful not to jump around with goto's too much. if you jump out of an if then block using goto, it causes memory leaks and will ultimately result in the dreaded ERR:MEMORY.

I'm sorry if it's hard to understand me, by the way. If you need simpler explanations I'll try.
What the reason is, is that you place some ":" directly after an "If", and then the "Then", which is not possible, because the "Then" must come directly after the "If"
What it looks like is something like this

Code:

::If A=1
::Then
:::Disp "A=1"
::End

Should be:

Code:

::If A=1:Then
:::Disp "A=1"
::End


EDIT: the first 3 lines you could better say:

Code:

For(L,0,100
......
End

which is much faster and takes less memory
PT_ wrote:
What the reason is, is that you place some ":" directly after an "If", and then the "Then", which is not possible, because the "Then" must come directly after the "If"
What it looks like is something like this

Code:

::If A=1
::Then
:::Disp "A=1"
::End

Should be:

Code:

::If A=1:Then
:::Disp "A=1"
::End


I came here to say exactly this Smile Be careful with your use of :
Not exactly on-topic, but I think the smallest possible FizzBuzz is this optimized version of http://tibasicdev.wikidot.com/forum/t-653960/compact-fizzbuzz:


Code:
For(F,1,ᴇ2
"FIZZ
If fPart(F/3
"_    //space
If not(fPart(F/5
Ans+"BUZZ
If Ans="_
F
Disp Ans
End


Can anyone go smaller? And does this even count, since spaces are displayed at the start of the lines?
lirtosiast wrote:
Not exactly on-topic, but I think the smallest possible FizzBuzz is this optimized version of http://tibasicdev.wikidot.com/forum/t-653960/compact-fizzbuzz:


Code:
For(F,1,ᴇ2
"FIZZ
If fPart(F/3
"_    //space
If not(fPart(F/5
Ans+"BUZZ
If Ans="_
F
Disp Ans
End


Can anyone go smaller? And does this even count, since spaces are displayed at the start of the lines?


That's really neat: I like it. I'm glad you're not trying to code for the version of Fizz-Buzz they got us to play when I was at school. You had to allow for how many times a number was divisible by 3 or 5, and how many digits 3 or 5 it contained. So for instance:
15 = FizzBuzzBuzz [mult. of both, contains a 5]
31 = Fizz [contains a 3]
33 = FizzFizzFizz [mult. of 3, contains two 3s]
45 = FizzFizzBuzzBuzz [mult. of 3^2, and of 5, and contains a 5]
etc.

In my teaching career, I've never tried getting classes to play this game, because I don't trust myself to pick up all their errors!
How can you prevent memory leaks? I'm having trouble with that in my programs as well.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement