Last C++ Question for a while
I've got my program pretty much completed except for the search algorithm. I need to let the user imput a name or partial name and search for it. I also need to let the user repeat this if they want. I'm pretty sure that means I need to make the search a function that way it is easily repeated. ANyway, I have no idea how to let the user search for a name or partial name. If anyone has any ideas please let me know. Also if you see anything wrong please tell me.
//This program will let the user imput names and phone numbers and will then let
//the user search for names and will display the reults. The user will then be able
//to repeat this if they desire.
#include <iostream>
#include <string>
using namespace std;
int main()
{
char Entries = 0;
char response[13];
char Numbers = 0;
char Search;
cout << "How many entries do you have? ";
cin.getline(response,256);
Entries = atoi(response);
string *PtrNames = new string[Entries];
string *PtrNumbers = new string[Entries];
for ( int row=0; row<Entries; row++)
{
cout << "Enter name #" << row+1 << " ";
cin.getline(response,13);
PtrNames[row] = response;
}
cout << "The " << Entries << " names that you entered are " << endl;
for (int row = 0; row<Entries; row++)
{
cout << PtrNames[row] << endl;
}
for ( int row=0; row<Entries; row++)
{
cout << "Enter Phone Number #" << row+1 << " ";
cin.getline(response,13);
PtrNumbers[row] = response;
}
for (int row =0; row<Entries; row ++)
{
for (int i=0; i<1; i++)
{
if (PtrNumbers[row][i] < '0' || PtrNumbers[row][i] >'9')
{
cout << "Phone number #"<< row+1<< " is invalid\n";
cout << "Please restart this program\n";
}
else
if
(PtrNumbers[row][4] != '-' && PtrNumbers[row][7] != '-')
{
cout << "Phone number #"<<row+1<< " is invalid\n";
}
}
}
cout << "The " << Entries << " phone numbers that you entered are " << endl;
for (int row = 0; row<Entries; row++)
{
cout << PtrNumbers[row] << endl;
}
cout << "What name would you like to search for?\n";
cin >> Search; //I have no idea where to go from here
int SeeResults;
cin >> SeeResults;
return 0;
}
|