When my program runs and i press 1 or 2 from the menu the function member_list or book_list runs but doesnt read any data from the text file it just prints out the cout statements a number of times. What i need it to do it display the records from the text file im reading into the program. Can anyone solve this problem ?
I believe i have opened them correctly in main() could it be that my functions to read them are wrong ?
please help??
Code:#include <iostream.h> #include <stdlib.h> #include <string> #include <fstream.h> const int maxmembers = 1000; const int maxbooks = 2000; struct cust { string surname; string house_no; string road; string ID; int books_borrowed; }; struct books { string author; string title; string category; string ISBN; int loaned; }; void member_list(cust c[]) { for(int i=0; i< maxbooks;i++) { cout<< "Surname\t\tHouse No\t\tRoad\t\tID" << endl; cout << c[i].surname << endl; cout << c[i].house_no << endl; cout << c[i].road << endl; cout << c[i].ID << endl; } } void book_list(books b[]) { for(int i=0; i< maxbooks;i++) { cout<< "Author\t\tTitle\t\tCategory\t\tISBN" << endl; cout << b[i].author << endl; cout << b[i].title << endl; cout << b[i].category << endl; cout << b[i].ISBN << endl; } } main() { char uTest[100]; int cRead = 0; int nTest[100]; //variables for type people and books books book[maxbooks]; cust user[maxmembers]; ifstream user_data; user_data.open("userdata.txt",ios::in); do { user_data.getline(uTest,100,';'); user[cRead].surname = uTest; user_data.getline(uTest,100,';'); user[cRead].house_no = uTest; user_data.getline(uTest,100,';'); user[cRead].road = uTest; user_data.getline(uTest,100,'\n'); user[cRead].ID = uTest; if (user_data) { cRead++; } }while (user_data && cRead <= maxmembers); user_data.close(); ifstream book_data; book_data.open("bookdata.txt",ios::in); do { book_data.getline(uTest,100,';'); book[cRead].author = uTest; book_data.getline(uTest,100,';'); book[cRead].title = uTest; book_data.getline(uTest,100,';'); book[cRead].category = uTest; book_data.getline(uTest,100,'\n'); book[cRead].ISBN = uTest; if (book_data) { cRead++; } }while (book_data && cRead <= maxbooks); book_data.close(); int choice; cout <<"Library Menu" << endl << endl ; cout <<"[1] List Library Members and Member Information" << endl; cout <<"[2] List Library Books and Book Information" << endl ; cout <<"[3] Issue Library Book" << endl ; cout <<"[4] Return Library Book" << endl ; cout <<"[5] Exit Library System" << endl ; cout <<"Enter Your Required Choice" << endl; cin >> choice; switch(choice) { case 1: member_list(user); break; case 2: book_list(book); break; case 5: exit(1); break; default: cout << "This is not an option" << endl; break; } }



LinkBack URL
About LinkBacks


