I need to write a program that prints a message for invalid cities. I keep getti
ID: 3764812 • Letter: I
Question
I need to write a program that prints a message for invalid cities. I keep getting error messages in my loop. I have all my variables declared it also must print a message "Not a city in Illinois" This is what I must start with.
' 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.
System.Console.WriteLine(mes_Not a city in Illinois)
' 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 ' Loop control variable
' Get user input
city = InputBox$("Enter city name: ")
' Write your loop here
For x = 0 To cityNames.Length - 1
If cityNames(x) = city Then
foundIt = True
End If
Next
' Write your test statement here to see if there is
' a match. Set the flag to true if city is found.
If foundIt Then
System.Console.WriteLine("City Found")
Else
System.Console.WriteLine("City not found in Illinois")
End If
Console.ReadKey()
' 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