First off this is a homework question, please don't do my homework for me as nice as that would be...
I have to make a program that can search a library for an author or title from a file and output all the matching lines. I am very close but right now the only thing my program works for is the very last author/title line. Here is my code:
// Get the file from the user
cout << "Welcome to the super duper programming library" << endl;
cout << "Enter in a file path: ";
getline(cin, userPath);
cout << endl;
// Call the loadData function
loadData(userPath);
// Create the menu
cout << "How would you like to search the library?" << endl
<< "Q to quit" << endl
<< "S to show all" << endl
<< "A to search by author" << endl
<< "T to search by title" << endl;
cout << "Choice: ";
cin >> userChoice;
// Switch to based on userChoice
switch (userChoice) {
case 'Q':
break;
case 'S':
cout << endl << "There are " << showAll(userPath) << " books in the library";
break;
case 'A':
cout << "Enter in the the author name: ";
cin >> searchA;
cout << endl << authorSearch(searchA, userPath);
}
cout << "Thanks for using Joe's library service";
// Pause and exit
getchar();
getchar();
return 0;
}
// loadData opens the specified file, and checks to make sure it is open
int loadData(string passedPath){
// Initialize neccesary ifstream variables
string line;
ifstream filePath;
// Open the file
filePath.open(passedPath.c_str());
// Return -1 if the file was entered wrong
if(!filePath.is_open()){
return -1;
}
first of all, this is not an issue, but where you wrote //initializing variables that is wrong. ur declaring variables. initializing is giving a variable an initial value for example int aramilsNumber = 10;. second since load data returns an int, you have to have an int variable equal the calculation of the function. i.e. aramilsNumber = loadData(userPath);. same with show all
so, whenever you give a function a return value, something has to hold that value. to make that happen you need to declare a variable with the same type as the return value and have it equal the function. if you don't want it to return a value then make it type void