none
Can you help me fix this error (EndIf) RRS feed

  • Question

  • 1 TextWindow.WriteLine("Type the values of three angles")
    2 x=TextWindow.ReadNumber()
    3 y=TextWindow.ReadNumber()
    4 z=TextWindow.ReadNumber()
    5
    6 If (x+y+z=180) Then
    7  If (x=90) Or (y=90) Or (z=90) Then
    8   TextWindow.WriteLine("That's a right-angled triangle")
    9  EndIf
    10 If x=y Or x=z Or y=z Then
    11  If x=y=z Then
    12    TextWindow.WriteLine("That's a equilateral triangle")
    13  Else
    14    TextWindow.WriteLine("That's a isosceles triangle")
    15    Else
    16    TextWindow.WriteLine("That's a scalene triangle")
    17  Else
    18  TextWindow.WriteLine("There's no triangle with those angles")
    19  EndIf
    20  EndIf
    21 EndIf
    

    It says it's expecting an EndIf statement in line 15 and that it isn't expecting it in line 21

    Any help is appreciated

    Tuesday, November 20, 2018 8:17 PM

Answers

  • TextWindow.WriteLine("Type the values of three angles")
    x=TextWindow.ReadNumber()
    y=TextWindow.ReadNumber()
    z=TextWindow.ReadNumber()
    
    If (x+y+z = 180) Then
      
      If (x=90) Or (y=90) Or (z=90) Then
        TextWindow.WriteLine("That's a right-angled triangle")
      Else
        
        If x=y Or x=z Or y=z Then
          If x=y And x=z Then
            TextWindow.WriteLine("That's a equilateral triangle")
          Else
            TextWindow.WriteLine("That's a isosceles triangle")
          EndIf
        Else
          TextWindow.WriteLine("That's a scalene triangle")
        EndIf
      EndIf
      
    Else
      TextWindow.WriteLine("There's no triangle with those angles")
    EndIf

    SB does'nt know  x=y=z !

    PS: A hint: Instead of going too deep into If-Else branches, you can try to get out as soon as possible.

    like:

    If (x+y+z <> 180) Then

      TextWindow.WriteLine("There's no triangle with those angles")

      Program.End()   '' or jump to a new beginning

    EndIf   '  and out

    ...

    work out the rest

    ..



    • Edited by Pappa LapubEditor Tuesday, November 20, 2018 9:19 PM
    • Marked as answer by edjfkf Tuesday, November 20, 2018 10:17 PM
    Tuesday, November 20, 2018 9:11 PM
    Answerer

All replies

  • TextWindow.WriteLine("Type the values of three angles")
    x=TextWindow.ReadNumber()
    y=TextWindow.ReadNumber()
    z=TextWindow.ReadNumber()
    
    If (x+y+z = 180) Then
      
      If (x=90) Or (y=90) Or (z=90) Then
        TextWindow.WriteLine("That's a right-angled triangle")
      Else
        
        If x=y Or x=z Or y=z Then
          If x=y And x=z Then
            TextWindow.WriteLine("That's a equilateral triangle")
          Else
            TextWindow.WriteLine("That's a isosceles triangle")
          EndIf
        Else
          TextWindow.WriteLine("That's a scalene triangle")
        EndIf
      EndIf
      
    Else
      TextWindow.WriteLine("There's no triangle with those angles")
    EndIf

    SB does'nt know  x=y=z !

    PS: A hint: Instead of going too deep into If-Else branches, you can try to get out as soon as possible.

    like:

    If (x+y+z <> 180) Then

      TextWindow.WriteLine("There's no triangle with those angles")

      Program.End()   '' or jump to a new beginning

    EndIf   '  and out

    ...

    work out the rest

    ..



    • Edited by Pappa LapubEditor Tuesday, November 20, 2018 9:19 PM
    • Marked as answer by edjfkf Tuesday, November 20, 2018 10:17 PM
    Tuesday, November 20, 2018 9:11 PM
    Answerer
  • Thanks! I tried replicating that x=y=z section in a very simple program. It shows no errors but it doesn't execute the code after "Then". I suppose another way would be "If x=y And x=z Then"...

    It seems weird to me that it doesn't throw an error for "x=y=z" since it doesn't understand it. Is there a particular reason?

    Tuesday, November 20, 2018 10:23 PM
  • You might consider using ElseIf. In some cases it can help simplify nested If Else Endif's.
    Tuesday, November 20, 2018 10:39 PM
  • about x=y=z,

    Try this:

    x = 1
    y = 1
    z = "True"  ' 1
    
    If x=y=z Then
      TextWindow.WriteLine("Hit")
    Else
      TextWindow.WriteLine("NO Hit")
    EndIf
    

    Set z = "True" , then set z=1 !!

    x=y=z  first solves the 1st part x=y  , which is "True", then it compares this "True" result like "True" = z

    If z is also "True" you have a hit, If z = 1   ->   "True" =? 1  ->  "False" (NO hit)


    Tuesday, November 20, 2018 11:05 PM
    Answerer