Question

I need to write a loop that examines the names of the cities stored in the...

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

0 0
Add a comment Improve this question Transcribed image text
Answer #1

' 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

Add a comment
Know the answer?
Add Answer to:
I need to write a loop that examines the names of the cities stored in the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Option Explicit On Option Strict On Module PayrollReport Sub Main() Dim Name As String Dim GrossString...

    Option Explicit On Option Strict On Module PayrollReport Sub Main() Dim Name As String Dim GrossString As String Dim Gross, Deduct, Net As Double Const RATE As Double = 0.25 Const QUIT As String = “XXX” Const REPORT_HEADING As String = “Payroll Report” Const END_LINE As String = “**End of report” ‘ Work done in the housekeeping() procedure System.Console.WriteLine(REPORT_HEADING) Name = InputBox$(“Enter employee’s name: “) While(Name <> QUIT) ‘ Work done in the detailLoop() procedure GrossString = InputBox$( _ “Enter...

  • Write the program in C The following statistics for cities of the Vege country are stored...

    Write the program in C The following statistics for cities of the Vege country are stored in a file: Name: a string of characters less than 15 characters long. Population: an integer value. Area: square miles of type double Write a program that: asks and gets the name of the input file from the user. Read the contents of the file into an array length 10 of structures -ask the user for the name of a city (less than 15...

  • Microsoft Excel VBA (Visual Basic for Applications) Programming Language Objectives: Create an array and redim it...

    Microsoft Excel VBA (Visual Basic for Applications) Programming Language Objectives: Create an array and redim it to a size equal to an assigned value of a variable, populate the array with a series of random numbers, output the array to a message box and to a worksheet. Instructions: - Review the variables already declared. You won't need others. - See comments in the code that will act as your guide. Add new code directly after each comment. - Assign a...

  • 7.2.3: Printing array elements with a for loop. Write a for loop to print all elements...

    7.2.3: Printing array elements with a for loop. Write a for loop to print all elements in courseGrades, following each element with a space (including the last). Print forwards, then backwards. End each loop with a newline. Ex: If courseGrades = {7, 9, 11, 10}, print: 7 9 11 10 10 11 9 7 Hint: Use two for loops. Second loop starts with i = courseGrades.length - 1. (Notes) Also note: If the submitted code tries to access an invalid...

  • I need help with this problem in Visual Basic 2012: Write a program that allows the...

    I need help with this problem in Visual Basic 2012: Write a program that allows the user to specify two numbers and then adds, subtracts, multiplies, or divides them when the user clicks on the appropriate button. The output should give the type of arithmetic performed and the result. Whenever one of the numbers in an input text box is changed, the output text box should be cleared. Also, if the number 0 is entered into the second text box,...

  • Parallel Arrays Summary In this lab, you use what you have learned about parallel arrays to...

    Parallel Arrays Summary In this lab, you use what you have learned about parallel arrays to complete a partially completed Java program. The program should either print the name and price for a coffee add-in from the Jumpin’ Jive coffee shop or it should print the message: "Sorry, we do not carry that.". Read the problem description carefully before you begin. The data file provided for this lab includes the necessary variable declarations and input statements. You need to write...

  • Write a while loop that prints userNum divided by 2 (integer division) until reaching 1. Follow...

    Write a while loop that prints userNum divided by 2 (integer division) until reaching 1. Follow each number by a space. Example output for userNum = 40: 20 10 5 2 1 Note: These activities may test code with different test values. This activity will perform four tests, with userNum = 40, then with userNum = 2, then with userNum = 0, then with userNum = -1. See "How to Use zyBooks". Also note: If the submitted code has an...

  • C programming only please 5.2.3: Printing array elements with a for loop. Write a for loop...

    C programming only please 5.2.3: Printing array elements with a for loop. Write a for loop to print all elements in courseGrades, following each element with a space (including the last). Print forwards, then backwards. End each loop with a newline. Ex: If courseGrades = {7, 9, 11, 10}, print: 7 9 11 10 10 11 9 7 Hint: Use two for loops. Second loop starts with i = NUM_VALS - 1. (Notes) Note: These activities may test code with...

  • Please help. I need a very simple code. For a CS 1 class. Write a program...

    Please help. I need a very simple code. For a CS 1 class. Write a program in Java and run it in BlueJ according to the following specifications: The program reads a text file with student records (first name, last name and grade). Then it prompts the user to enter a command, executes the command and loops. The commands are the following: "printall" - prints all student records (first name, last name, grade). "firstname name" - prints all students with...

  • Write a loop that sets newScores to oldScores shifted once left, with element 0 copied to...

    Write a loop that sets newScores to oldScores shifted once left, with element 0 copied to the end. Ex: If oldScores = {10, 20, 30, 40), then newScores = {20, 30, 40, 10). Note: These activities may test code with different test values. This activity will perform two tests, both with a 4-element array (int oldScores[4]). See "How to Use zyBooks". Also note: If the submitted code tries to access an invalid array element, such as newScores[9] for a 4-element...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT