how do i get my fuctions to return back to main. when it runs my function ends e.g. the member_list function after operation i want it to go back to main because thats where my menu is the program is supposed to finsih when the user presses 5.
can anyone tell me then how i get my function to return to main.
ive tried putting the menu outside main but i get errors
Code:
#include <iostream.h>
#include <stdlib.h>
#include <string>
#include <fstream.h>
const int maxmembers = 15;
const int maxbooks = 30;
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;
};
int member_list(cust c[])
{
for(int i=0; i< maxmembers;i++)
{
cout<< "Surname\t\tHouse No\tRoad\t\tID" << endl;
cout << c[i].surname;
cout << c[i].house_no;
cout << c[i].road;
cout << c[i].ID << endl;
}
}
int book_list(books b[])
{
for(int i=0; i< maxbooks;i++)
{
cout<< "Author\t\t\tTitle\t\t\tCategory\tISBN" << endl;
cout << b[i].author ;
cout << b[i].title ;
cout << b[i].category;
cout << b[i].ISBN << endl;
}
}
void issue_book(books b [], cust c[])
{
string member = 0;
string ISBN = 0;
cout << "Please enter ISBN number of book: " << endl;
cin >> ISBN ;
cout << "Please enter member ID: " << endl;
cin >> member;
for(int i=0; i < maxbooks; i++)
{
if (b[i].ISBN == ISBN)
{
b[i].loaned ++;
}
}
for(int i=0; i < maxmembers; i++)
{
if(c[i].ID == member)
{
c[i].books_borrowed ++;
}
}
//save_book(b);
//save_user(c);
}
void return_book(books b[], cust c[])
{
string member = 0;
string ISBN = 0;
cout << "Please enter ISBN number of book: " << endl;
cin >> ISBN ;
cout << "Please enter member ID: " << endl;
cin >> member;
for(int i=0; i < maxbooks; i++)
{
if (b[i].ISBN == ISBN)
{
b[i].loaned --;
}
}
for(int i=0; i < maxmembers; i++)
{
if(c[i].ID == member)
{
c[i].books_borrowed --;
}
}
//save_book();
//save_user();
}
/*void save_book(books b[])
{
ofstream book_data;
if (book_data.is_open())
{
for(int i=0; i < maxbooks;i++)
{
book_data << b[i].author;
book_data << ";";
book_data << b[i].title;
book_data << ";";
book_data << b[i].category;
book_data << ";";
book_data << b[i].ISBN;
book_data << ";";
book_data << b[i].loaned;
book_data << ";";
}
book_data.close();
}
}*/
/*void save_user(cust c[])
{
ofstream user_data;
if (user_data.is_open())
{
for(int i=0; i < maxmembers;i++)
{
user_data << c[i].surname;
user_data << ";";
user_data << c[i].house_no;
user_data << ";";
user_data << c[i].road;
user_data << ";";
user_data << c[i].ID;
user_data << ";";
user_data << c[i].books_borrowed;
user_data << ";";
}
user_data.close();
{
}*/
int main()
{
//variables for type people and books
books book[maxbooks];
cust user[maxmembers];
char uTest[1000];
int cRead = 0;
int nTest = 100;
ifstream user_data;
user_data.open("userdata.txt",ios::in);
do
{
user_data.getline(uTest,nTest,';');
user[cRead].surname = uTest;
user_data.getline(uTest,nTest,';');
user[cRead].house_no = uTest;
user_data.getline(uTest,nTest,';');
user[cRead].road = uTest;
user_data.getline(uTest,nTest,'\n');
user[cRead].ID = uTest;
if (user_data)
{ int nTest[100];
cRead++;
}
}while (user_data && cRead < maxmembers);
user_data.close();
ifstream book_data;
book_data.open("bookdata.txt",ios::in);
do
{
book_data.getline(uTest,nTest,';');
book[cRead].author = uTest;
book_data.getline(uTest,nTest,';');
book[cRead].title = uTest;
book_data.getline(uTest,nTest,';');
book[cRead].category = uTest;
book_data.getline(uTest,nTest,'\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 3:
issue_book(book,user);
break;
case 4:
return_book(book,user);
break;
case 5:
exit(1);
break;
default:
cout << "This is not an option" << endl;
break;
}
}