In the mean time, here is a starter. See if it is any use to you.
Code:
#include <iostream>
#include <cstring>
#include <conio.h>
#include <cstdlib>
//-- using std::cout;
using std::cin;
using std::endl;
using std::getline;
using std::string;
//-- struct Contact
{
string name;
string number;
};
int main()
{
std::size_t RecordSize = 3;
/*cout<<"Enter number of Contact entries: ";
cin>>RecordSize;
cin.get();*/
Contact* ContactRecord = new Contact[RecordSize];
/*for(std::size_t i = 0; i < RecordSize; ++i)
{
cout<<"Enter Name: ";
getline(cin, ContactRecord[i].name);
cout<<"Phone number ";
cin>>ContactRecord[i].number;
cin.get();
}*/
ContactRecord[0].name = "Val"; ContactRecord[0].number = "123";
ContactRecord[1].name = "Alex"; ContactRecord[1].number = "456";
ContactRecord[2].name = "Val"; ContactRecord[2].number = "789";
system("cls");
//Let's review all Contact Records.
cout<<"Current Contact Records:"<<endl;
for (std::size_t i = 0; i < RecordSize; ++i)
{
cout<<ContactRecord[i].name<<" "<<ContactRecord[i].number<<endl;
}
char MenuController ;
string ContactName;
bool FoundContacts(false);
//Contact lookup menu loop. while(true)
{
cout<<endl;
cout<<"Would you like to lookup a contact (y = yes, other = no)?"<<endl;
cin.get(MenuController);
cin.get();
system("cls");
if(MenuController != 'y')
{
//User does not want to lookup contacts: exit contact lookup menu loop. break;
}
//User wants to lookup contacts.
cout<<"Enter the name of the contact."<<endl;
getline(cin, ContactName);
for(std::size_t i = 0; i < RecordSize; ++i)
{
if(ContactRecord[i].name == ContactName)
{
FoundContacts = true;
cout<<"Found match in record "<<i+1<<": "<<ContactName<<" - "
<<ContactRecord[i].number<<endl;
}
}
if(FoundContacts == false)
{
cout<<"No contacts found with the specified name."<<endl;
}
FoundContacts = false;
}
//Free the memory resources. Observe square brackets in delete[]. delete[] ContactRecord;
return 0;
}