I have created the following code and I need some guidance on how to correct my error. The code is as follows:
Code:
#include <string>
#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;
const int MAX_BOOKS = 2000;
const int MAX_USERS = 500;
struct User
{
string userID;
string name;
string houseNo;
string address;
string noOfLoans;
};
struct Book
{
string bookID;
string title;
string authorSurname;
string authorFirstname;
string category;
string location;
string onLoan;
};
enum bookCategory
{
Adventure = 'A',
Detective = 'D',
SciFi = 'S',
Romance = 'R'
};
int findBookAuthor(Book[], string, int);
int main()
{
ifstream bookDataFile;
ifstream userDataFile;
Book books[MAX_BOOKS];
User users[MAX_USERS];
int noOfBooks = 0;
int noOfUsers = 0;
bookDataFile.open("bookdata.txt");
userDataFile.open("userdata.txt");
while(!bookDataFile.eof() && noOfBooks < MAX_BOOKS)
{
getline(bookDataFile, books[noOfBooks].authorSurname);
getline(bookDataFile, books[noOfBooks].authorFirstname);
getline(bookDataFile, books[noOfBooks].title);
getline(bookDataFile, books[noOfBooks].category);
getline(bookDataFile, books[noOfBooks].bookID);
if (! bookDataFile.eof())
noOfBooks++;
}
bookDataFile.close();
string author;
int bookID;
int option;
while(true)
{
cout << "1. Loan Book" << endl;
cout << "2. Find Book By Author" << endl;
cin >> option;
switch(option)
{
case 1:
cout << "Under Construction" << endl;
break;
case 2:
cout << "Enter Author Name: ";
cin >> author;
bookID = findBookAuthor(books, author, noOfBooks);
break;
}
}
return 0;
}
int findBookAuthor(Book books[], string author, int noOfBooks)
{
for(int bookNo = 0; bookNo < noOfBooks; bookNo++)
{
if(books[bookNo].authorSurname == author)
{
cout << "--------------------------------------------------" << endl;
cout << "BookID: " << books[bookNo].bookID << endl;
cout << "Title: " << books[bookNo].title << endl;
cout << "Author: " << books[bookNo].authorSurname << "," << books[bookNo].authorFirstname<< endl;
cout << "Category: " << books[bookNo].category << endl;
cout << "Location: " << books[bookNo].location << endl;
cout << "onLoan: " << books[bookNo].onLoan << endl;
cout << "--------------------------------------------------" << endl << endl;
}
}
return -1;
}
int findUser(User users[], string userName, int noOfUsers)
{
for(int userID = 0; userID < noOfUsers; userID++)
{
if(users[userName].name == users)
{
cout << "--------------------------------------------------" << endl;
cout << "UserID: " << users[userID].userID << endl;
cout << "Name: " << users[userID].name << endl;
cout << "House No: " << users[userID].houseNo << endl;
cout << "Address: " << users[userID].address << endl;
cout << "No of Loans: " << users[userID].noOfLoans << endl;
cout << "--------------------------------------------------" << endl << endl;
}
}
return -1;
}
The error I am getting is around this area:
Code:
for(int userID = 0; userID < noOfUsers; userID++)
{
if(users[userName].name == users)
{
cout << "--------------------------------------------------" << endl;
cout << "UserID: " << users[userID].userID << endl;
cout << "Name: " << users[userID].name << endl;
cout << "House No: " << users[userID].houseNo << endl;
cout << "Address: " << users[userID].address << endl;
cout << "No of Loans: " << users[userID].noOfLoans << endl;
cout << "--------------------------------------------------" << endl << endl;
}
}
return -1;
And the error message I am receiving is:
Code:
In function `int findUser(User *, basic_string<char,string_char_traits<char>,__default_alloc_template<false,0> >, int)':
library.cc:114: no match for `User *&[string &]'
Can someone please guide me on how to fix this problem, thanks in advance.