What's wrong with my code?

ArcadeUser 21 Reputation points
2022-01-24T22:43:18.947+00:00

TextWindow.WriteLine("Enter a year to determine whether or not the year is a leap one or not!")
eyear = TextWindow.ReadNumber()

dby4 = Math.Remainder(eyear, 4)
dby100 = Math.Remainder(eyear, 100)

Divisibleby4:
If dby4 = 0 Then
TextWindow.WriteLine("That's a leap year!")
Goto Dby100
Else
TextWindow.WriteLine("That's not a leap year.")
EndIf
Dby100:
If dby100 = 0 Then
TextWindow.WriteLine("That's not a leap year.")
ElseIf dby100 > 0 Then
TextWindow.WriteLine("That's a leap year!")
Goto Divisibleby4
EndIf

It keeps doing this when I type 1604 (the program is to determine whether or not the year you type is a leap year or not):

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

2 answers

Sort by: Most helpful
  1. Kristian Virtanen 126 Reputation points
    2022-01-24T23:04:17.177+00:00

    Hi.

    Seems like your program logic is a bit lost here. Lets fix it ;)

    Leap year is every fourth year and last time it was 2020. So next time its 2024. This way we only need to know the remainder by 4.

    begin:  
    TextWindow.WriteLine("Enter a year to determine whether or not the year is a leap one or not!")  
    eyear = TextWindow.ReadNumber()  
    dby4 = Math.Remainder(eyear, 4)  
      
    If dby4 = 0 Then   
      TextWindow.WriteLine("That's a leap year!")  
    Else  
      TextWindow.WriteLine("Nope, thats not a leap year!")  
    EndIf  
      
    Goto begin  
      
    

    168071-image.png


  2. Scout 541 Reputation points
    2022-02-16T22:23:44.483+00:00

    Demo - Simulation of Leap Year Calculation: PLFS370.000

    GraphicsWindow.Title = "Leap Year Simulation" ' PLFS370.000'  
    GraphicsWindow.Height = 800  
    GraphicsWindow.Width  = 800  
    year = 2022  
    center = 392  
    radius = 291  
    pin = 310  
    daystep = 2 * Math.Pi / 365.24219  
    uni  =LDShapes.BrushGradient("1=gold;2=Yellow;3=black;4=black;5=black;6=black;7=black;8=black;9=navy;10=black;11=black;12=black" , "")  
    earth=LDShapes.BrushGradient("1=white;2=white;3=lime;4=green;5=brown;6=saddlebrown;7=blue;8=blue;9=white;10=white" , "DD")  
    bullet=LDShapes.BrushGradient("3=white;1=white;2=blue" , "DD")  
    LDGraphicsWindow.BackgroundBrush(uni)  
    board = Shapes.AddText(year)  
    Shapes.Move(board,center-7,66)  
    planet = Shapes.AddEllipse(18,18)  
    ball = Shapes.AddEllipse(16,16)  
    LDShapes.BrushShape(planet,earth)  
    LDShapes.BrushShape(ball,bullet)  
    LDShapes.Move(planet,center,center-pin)  
    x=center + Math.Sin(Math.Pi*1.999)*radius  
    y=center - Math.Cos(Math.Pi*1.999)*radius  
    LDShapes.Move(ball,x,y)  
    Program.Delay(1000)  
    x=392  
    y=101  
    LDShapes.Move(ball,x,y)  
    Position = 2 * Math.Pi  
    While 1=1  
      For i = 1 to 365  
       Position = Position + daystep  
       x=center + Math.Sin(Position)*radius  
       y=center - Math.Cos(Position)*radius  
       LDShapes.Move(ball,x,y)  
       Program.Delay(1)  
      EndFor  
      dby4   = Math.Remainder(year, 4)  
      dby100 = Math.Remainder(year, 100)  
      dby400 = Math.Remainder(year, 400)  
      If (dby4 = 0) AND (dby100 <> 0 OR dby400 = 0 ) Then  
       Position = Position + daystep  
       x=center + Math.Sin(Position)*radius  
       y=center - Math.Cos(Position)*radius  
       LDShapes.Move(ball,x,y)       
      EndIf  
      xpin = center + Math.Sin(Position)*pin  
      ypin = center - Math.Cos(Position)*pin  
      LDShapes.Move(planet,xpin,ypin)  
      Program.Delay(1)  
      year = year + 1  
      Shapes.SetText(board,year)  
    EndWhile  
    

    175163-leapyear.jpg

    0 comments No comments