Here is my code
#include <iostream>
using namespace std;
int searchList(int [], int, int);
int main()
{
int numItems = 18;
int position;
int accountnumber;
int accounts[numItems] = {5658845, 4520125, 7895122,8777541, 8451277, 1302850,8080152, 4562555, 5552012,
5050552, 7825877, 1250255,1005231, 6545231, 3852085,7576651, 7881200, 4581002 };
cout << "Please enter an account charge number: ";
cin >> accountnumber;
position = searchList( accounts, numItems, accountnumber);
if(position == -1)
cout << accountnumber "Is not a valid charge account number." << endl;
else
cout << accountnumber "Is a valid charge account number." << endl;
return 0;
}
int searchList(int accounts[],int numItems,int accountnumber)
{
int index = 0;
int position = -1;
bool found = false;
while(!found && index < numItems)
{
if(accounts[index] == accountnumber)
{
found = true;
position = index;
}
index++;
}
return position;
}
The Errors i get are
C:\Users\***\Desktop\prelab1.cpp In function `int main()':
15 C:\Users\***\Desktop\prelab1.cpp variable-sized object `accounts' may not be initialized
23 C:\Users\***\Desktop\prelab1.cpp expected `;' before string constant
25 C:\Users\***\Desktop\prelab1.cpp expected `;' before string constant
Any help would be much appreciated.