Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

has anyone found a solution too this problem yet? i am currently having problems

ID: 3862156 • Letter: H

Question

has anyone found a solution too this problem yet? i am currently having problems with it myself.

The program uses a list that contains valid names for 10 cities in Michigan. You ask the user to enter a city name; your program then searches the list 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 starter file provided for this lab includes input statements. You need to use a loop to examine all the items in the list and test for a match. You also need to set a flag if there is a match and then test the flag variable to determine if you should print the "Not a city in Michigan." message.

Comments in the code tell you where to write your statements.

Instructions

Study the prewritten code to make sure you understand it.

Write a loop statement that examines the names of cities stored in the list.

Write code that tests for a match.

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

Execute the program using the following as input:

Explanation / Answer

#include<iostream>
using namespace std;
int main()
{
   //list declaration...cities in michigan
   string c,cities[] = {"Detroit","Lansing","Flint","Kalamazoo","Dearborn","Traverse City","Saginaw","Novl","Muskegon","Royal Oak"};
  
   cout<<"Enter a city name in michigan:";//prompting for input
  
   getline(cin,c);//reading string
  
   int flag=0,i;
  
   i=0;
   while(i<10)//loop to match with cities
   {
       if(cities[i]==c)//matching..
       {
       flag=1;//if city found  
       break;
       }
       i++;
   }
   if(flag==0)///printing output
   {
       cout<<"Not a city in Michigan ";  
   }
   else
   {
       cout<<"City in Michigan ";  
   }
  
  
  
   return 0;
  
}

output:-

Enter a city name in michigan:Noid
Not a city in Michigan


Process exited normally.
Press any key to continue . . .

Enter a city name in michigan:Detroit
City in Michigan


Process exited normally.
Press any key to continue . . .