I need to take the username entered by the user and compare it to the array to locate its position in the array then compare the password and pin entered by the user. I followed tutorials on how to write the linear search function(I do have to use a linear search) and when i go to compile i get 2 errors. These:
"c:\users\andrew\documents\visual studio 2010\projects\test3\test3\wheel.cpp(92): error C2601: 'searchList' : local function definitions are illegal
c:\users\andrew\documents\visual studio 2010\projects\test3\test3\wheel.cpp(83): this line contains a '{' which has not yet been matched"
Here's my code thus far:
#include <string>
#include <fstream>
#include <iostream>
#include <iomanip>
using namespace std;
/*Function Protottypes*/
void OpenFile();
void ProcessFile();
void CheckLogin();
int searchList(string[], int, string);
/*Constants*/
const int MAX_USERS = 50;
int position;
int count;
int currentUsers;
int userpinGuess;
ifstream inFile;
string usernameGuess;
string passwordGuess;
/*Struct to store data*/
struct UserLogin
{
string userName;
string passWord;
int userPin;
};
int main()
{
OpenFile();
ProcessFile();
CheckLogin();
cout << position << endl;
return 0;
}
void OpenFile()
{
inFile.open("users.txt");
while(!inFile) //loop to notify user of invalid file
{
cout << "Error: File not found. " << endl; // invalid entry occurred
// message is printed
}
}
void ProcessFile()
{
inFile >> currentUsers;
UserLogin loginInfo[MAX_USERS];
for (count = 0; count < currentUsers; count++) // loop to read data from file
{
inFile >> loginInfo[count].userName;
inFile >> loginInfo[count].passWord;
inFile >> loginInfo[count].userPin;
}
cout << "Your current number of users is: " << currentUsers << endl << endl;
cout << "Username" << setw(12) << "Password" << setw(8) << "Pin" << endl;
cout << "________" << setw(12) << "________" << setw(8) << "___" << endl;
for (count = 0; count < currentUsers; count++)
{
cout << loginInfo[count].userName << setw(14) << loginInfo[count].passWord << setw(9) << loginInfo[count].userPin << endl;
}
}
void CheckLogin()
{
cout << "Please enter your username: " ;
cin >> usernameGuess;
cout << "Please enter your password: " ;
cin >> passwordGuess;
cout << "Please enter your pin: " ;
cin >> userpinGuess;
int searchList(string loginInfo[], int currentUsers, string usernameGuess)
{
int index = 0;
int position = -1;
bool found = false;
while(index < currentUsers &&!found)
{
if (loginInfo[index] == usernameGuess)
{
found = true;
position = index;
}
index++;
}
return position;
}
}
Also there's a red squigly line under the "{" after the searchList that says it expected a ";", but when I add one in it causes even more problems.
I've read many guides and the book for my class but I still can't figure out what I'm missing.Any help would be greatly appreciated.