Question: The program uses an array that contains valid names for 10 cities in Michigan. Ask the user to enter a city name; the program then

The program uses an array that contains valid names for 10 cities in Michigan. Ask the user to enter a city name; the program then searches the array for that city name. If it is not found, the program should print a message that informs the user the city name is not found in the list of valid cities in Michigan.

The file provided for this lab includes the input statements and the necessary variable declarations. Use a loop to examine all the items in the array and test for a match. Also need to set a flag if there is a match and then test the flag variable to determine if it should print the the Not a city in Michigan. message. Comments in the code tell where to write the statements. Use the previous Mail Order program as a guide.

0. Ensure the provided code file namedMichiganCities.cppis open.

1. Study the prewritten code to make sure you understand it.

2. Write the loop statement that examines the names of cities stored in the array.

3. Write code that tests for a match.

4. Write code that, when appropriate, prints the message Not a city in Michigan..

5. Execute the program by clicking theRunbutton at the bottom of the screen. Use the following as input:

Chicago

Brooklyn

Watervliet

Acme

DRAFT:

// MichiganCities.cpp - This program prints a message for invalid cities in Michigan.

// Input: Interactive

// Output: Error message or nothing

#include

#include

using namespace std;

int main()

{

// Declare variables

string inCity; // name of city to look up in array

const int NUM_CITIES = 10;

// Initialized array of cities

string citiesInMichigan[] = {"Acme", "Albion", "Detroit", "Watervliet", "Coloma", "Saginaw", "Richland", "Glenn", "Midland", "Brooklyn"};

bool foundIt = false; // Flag variable

int x; // Loop control variable

// Get user input

cout

cin >> inCity;

// Write the loop here

// Write the 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.

return 0;

} // End of main()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Mathematics Questions!