I need to write a loop that examines the names of the cities stored in the array
ID: 3764734 • Letter: I
Question
I need to write a loop that examines the names of the cities stored in the array.
Write code that tests for a match
Write code that, when appropriate, prints the message: Not a city in Illinois
_______________________________________________________________
' IllinoisCities.vb - This program prints a message for invalid cities in Illinois.
' Input: Interactive
' Output: Error message or nothing
Option Explicit On
Option Strict On
Module IllinoisCities
Sub Main()
' Declare variables.
Dim city As String ' city to look up in array
' Initialized array of Illinois cities
Dim cityNames() As String = {"Chicago", "Peoria", "Alton", "Springfield", "Batavia", "Naperville", "Kankakee", "Lisle", "Decatur", "Normal"}
Dim foundIt As Boolean = False ' Flag variable
Dim x As Integer ' Loop control variable
' Get user input
city = InputBox$("Enter city name: ")
' Write your loop here
' Write your test statement here to see if there is
' a match. Set the flag to true if city is found.
' Test to see if city was not found to determine if
' "Not a city in Illinois" message should be printed
End Sub ' End of Main() procedure
End Module ' End of IllinoisCities module
Explanation / Answer
' IllinoisCities.vb - This program prints a message for invalid cities in Illinois.
' Input: Interactive
' Output: Error message or nothing
Option Explicit On
Option Strict On
Module IllinoisCities
Sub Main()
' Declare variables.
Dim city As String ' city to look up in array
' Initialized array of Illinois cities
Dim cityNames() As String = {"Chicago", "Peoria", "Alton", "Springfield", "Batavia", "Naperville", "Kankakee", "Lisle", "Decatur", "Normal"}
Dim foundIt As Boolean = False ' Flag variable
Dim x As Integer=0 ' Loop control variable
' Get user input
city = InputBox$("Enter city name: ")
' Write your loop here
while x<=cityNames.Length
' Write your test statement here to see if there is
' a match. Set the flag to true if city is found.
If StrComp(city,cityNames(x), CompareMethod.Text)=0 Then
foundIt=True
Exit While
End If
x=x+1
End while
' Test to see if city was not found to determine if
' "Not a city in Illinois" message should be printed
If foundIt=True then
MsgBox("City in Illinois")
Else
MsgBox("Not a City in Illinois")
End if
End Sub ' End of Main() procedure
End Module ' End of IllinoisCities module