Attached is a text file full of names. Write a program that prompts the user to type in a name. If the name appears in the list of names, the program prints a message indicating the name was found. If the name entered by the user is not in the database, the program prints a different message indicating the name was not found. The program will continue prompting the user and searching for names until the user enters "quit".
The text file is named: names_fall2020.txt
Please solve using C++
Thanks!
C++ code
#include<iostream>
#include<fstream>
using namespace std;
int main(){
string name, userInput;
bool found;
ifstream in;
while(1){
found = false;
in.open("names_fall2020.txt");
cout<<"Enter name to search :
";
getline(cin , userInput);
if(userInput == "quit")
break;
while(getline(in , name)){
if(name ==
userInput){
found = true;
break;
}
}
if(found){
cout<<userInput<<" found in database \n";
}
else cout<<userInput<<"
not found in database\n";
in.close();
}
in.close();
return 0;
}
Get Answers For Free
Most questions answered within 1 hours.