none
Collect two pieces of information in an array and then feed back one piece based on the other piece RRS feed

  • Question

  • Code I've been trying to use

    For i = 1 To 4
      TextWindow.Write("user" + i + ", enter name ")
      name[i] = TextWindow.Read()
      TextWindow.Write("Enter birthdate ")
      birthdate[i] = TextWindow.Read()
    EndFor
    Begin:
    TextWindow.Write("For which person do you wish info?")
    user = TextWindow.Read()
    If name[1] = name[user] Then
      TextWindow.WriteLine(name[1] + "'s birthdate is " + birthdate[1])
    ElseIf name[2] = name[user] Then
      TextWindow.WriteLine(name[2] + "'s birthdate is " + birthdate[2])
     ElseIf name[3] = name[user] Then
      TextWindow.WriteLine(name[3] + "'s birthdate is " + birthdate[3])
     Else
        TextWindow.WriteLine(name[4] + "'s birthdate is " + birthdate[4])
    EndIf
      Goto Begin

    The code always give the birthdate of the last person, not the birthdate of the user read.


    Robert Crysler

    Wednesday, March 2, 2016 12:57 PM

Answers

  • You should replace  name[user] by user. You read the name of the user into the variable user! The array value name[user] is undefined ( "" ) and thus never equal the one of the name[1..4]

    Jan [ WhTurner ] The Netherlands


    Wednesday, March 2, 2016 3:50 PM
    Answerer

All replies

  • You should replace  name[user] by user. You read the name of the user into the variable user! The array value name[user] is undefined ( "" ) and thus never equal the one of the name[1..4]

    Jan [ WhTurner ] The Netherlands


    Wednesday, March 2, 2016 3:50 PM
    Answerer
  • I finally figured out the correct code myself.  It is below.

    For i = 1 To 4
      TextWindow.Write("user" + i + ", enter name ")
      name[i] = TextWindow.Read()
      TextWindow.Write("Enter birthdate ")
      birthdate[i] = TextWindow.Read()
    EndFor

    Begin:
    TextWindow.Write("For which person do you wish info?")
    user = TextWindow.Read()
    If name[1] = user Then
      TextWindow.WriteLine(user + "'s birthdate is " + birthdate[1])
    ElseIf name[2] = user Then
      TextWindow.WriteLine(user + "'s birthdate is " + birthdate[2])
    Elseif name[3] = user Then
      TextWindow.WriteLine(user + "'s birthdate is " + birthdate[3])
    Else
      TextWindow.WriteLine(user + "'s birthdate is " + birthdate[4])
    EndIf
      Goto Begin


    Robert Crysler

    Wednesday, March 2, 2016 9:33 PM
  • Thank you and that is what I finally figured out myself as I looked at it again.

    RC


    Robert Crysler

    Wednesday, March 2, 2016 9:34 PM