Question: The data file provided for this lab inlcudes the input statement and the necessary variable declarations. you need to use a loop to examine all
The data file provided for this lab inlcudes the input statement and the necessary variable declarations. you need to use a loop to examine all the items in the array and test for a match.
you also need to set if there is a match and then test the flag variable to determine if the program should print the "Not a city Michigan" message. comments in the code tll you where to write your statements. you can use the mail order program in this chapter as a guide.
1. open the source code file name Michigancities.vb.
2.study the prewritten code to make sure you understand it.
3.write a loop statement that examines the names of the cities stored in the array..
4. write a code that test for a match.
5.write code that when appropriate,print the message. "Not a city in michigan"
6.save this code file in a directory of your choice.
7.compile the source code file Michigancities.vb
8.execute program using the following as input.
Chigago
Brooklyn
Watervliet
Acme
_______________________________
Prewritten code:
' MichiganCities.vb - This program prints a message for invalid cities in Michigan.
' Input: Interactive
' Output: Error message or nothing
Option Explicit On
Option Strict On
Module MichiganCities
Sub Main()
' Declare variables.
Dim City As String ' city to look up in array
' Initialized array of Michigan cities
Dim CityNames() As String = {"Acme", "Albion", "Detroit", "Watervliet", "Coloma", "Saginaw", "Richland", "Glenn", "Midland", "Brooklyn"}
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 Michigan" message should be printed
End Sub ' End of Main() procedure
End Module ' End of MichiganCities module
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
