I'm trying to create a program that opens an input file containing a telephoning directory, prompt the user for a first and last name, search and retrieve the proper name with the number attatched, and display the name. Then prompts the user to either try a new name or end program. My code is provided below but I am stumped.., I keep getting programming errors... Oh and it's C++.
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstring>
#include <cmath>
using namespace std;
void NamePrompt(string&, string&);
void SearchName(string&, string);
int main()
{
ifstream myInfile;
myInfile.open ("input.txt");
if (!myInfile)
{
cout<< "Can't open the input file. Try a different file later."<<endl;
cout<< "Program terminated.";
return 1;
}
int process;
process = 1;
while(process==1)
{
string userChoice;
string nameMatch;
NamePrompt(userChoice);
SearchName(nameMatch);
if(!nameMatch)
{
cout<< "Name not found."<<endl;
cout<< "Would you like to search for a different name?";
cout<< "If yes, type 1. Otherwise, input any other numerical value to end program.";
cin>>process;
if (process!=1)
{
cout<< "Thank you for using TeleDirect. Goodbye.";
char exit_char;
cout<< "Press any char and <enter> to exit.";
cin>>exit_char;
}
}
cout<< "The match is...,";
cout<<endl;
cout<<nameMatch;
cout<<endl<< "Hopefully this is the right match..."<<endl;
cout<< "Would you like to try a different search?"<<endl;
cout<< "If yes, type 1. Otherwise, input any other numerical value to end program.";
cin>>process;
}
myInfile.close();
return 0;
}
//************************************************** *************************//
void NameMatch(string& firstName, string& lastName)
{
string firstName;
string lastName;
cout<< "Enter the person's first name: ";
cin>>firstName;
cout<< "Enter the person's last name :";
cin>>lastName;
userChoice = firstName+' '+lastName;
}
//************************************************** *************************//
void SearchName(string& nameMatch, string userChoice)
{
nameMatch= cin.getline(cin, userChoice);
}