Question: *****This is the error message I am getting now MichiganCities.cpp: In function int main(): MichiganCities.cpp:17:8: warning: unused variable x [-Wunused-variable] int x; // Loop control

*****This is the error message I am getting now

MichiganCities.cpp: In function int main(): MichiganCities.cpp:17:8: warning: unused variable x [-Wunused-variable] int x; // Loop control variable ^ Enter name of city:

// 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 << "Enter name of city: ";

cin >> inCity;

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

for (int i = 0; i < NUM_CITIES; i++) {

if (citiesInMichigan[i] == inCity) {

foundIt = true;

break;

}

}

// Test the flag variable to see if the city was found

if (foundIt) {

cout << "The city of " << inCity << " is in Michigan." << endl;

} else {

cout << "Not a city in Michigan." << endl;

}

// Write your loop here

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 Databases Questions!