I've started programming using C++ few weeks back. I'm working on an application store user input data into an array list. When entering user data the application must be able to check whether the user already exists in the array list. The program is unable to store the user input or able to check whether the user already exists in the array list..
int linearSearch(int array[], int size, int searchValue)
{
for (int i = 0; i < size; i++)
{
if (searchValue == array[i])
{
return i;
break;
}
}
return -1;
}
void customerReg(){
const int Capacity = 99;
int cnic[Capacity];
int customerNic;
int search = 0;
cout << "Enter Customer NIC: \n";
cin >> cnic[Capacity];
search = linearSearch(cnic, Capacity, customerNic);
if (search != -1){
cout << "Customer is already registered!\n";
}
else {
string customerName;
cout << "Enter Customer Name: \n";
cin >> customerName;
}
cnic. So, when you first search it, you may find the value or not, as the values are undefined (could be anything).cnicarray. I recommend usingstd::vectorand not using arrays.