write a program to initialize any array of 5 names and initialize another array with their respective telephone numbers. Search for a name( by using liners search) input by the user, in the list. if found, display " search successful " and print the name along with the telephone number. if not found display " search unsuccessful. name is not enlisted".
Answers
Answered by
3
Program :
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
int flag = 0;
string search;
string name[5];
long long phone[5];
for(int i = 0 ; i < 5 ; i++)
{
cout<<"Enter a name : ";
cin>>name[i];
cout<<"Enter a phone num_ber : ";
cin>>phone[i];
}
cout<<"Enter a name to be searched : ";
cin>>search;
for(int i = 0 ; i < 5 ; i++)
{
if(search.compare(name[i]) == 0)
{
cout<<"Search successful"<<endl;
cout<<name[i]<<" : "<<phone[i];
flag = 1;
break;
}
}
if(flag == 0)
{
cout<<"Search unsuccessful. Name is not enlisted";
}
return 0;
}
Similar questions