here is my code
Code:
#include <iostream.h>
#include <fstream.h>
#include <stdio.h>
#include <conio.h>
#include <string.h>
#define MAX 10
char choice;
char type;
int i;
//-----------------------------------
//base and derived classes
class books {
public:
struct database {
char title[256];
char author[256];
char isbn[11];
char publishername[256];
char cdrom[4];
char yearofpub[5];
char price[5];
}np[MAX]; // end of struct
//..........................
void find(void);
void enter(int);
void remove(void);
void first(void);
void list(void);
};
//------------------------------------
class store: public books{
public:
void save(void);
void load(void);
};
char name[12]="peter minns";
//------------------------------------
int main(int) {
int x=1;
books bdata;
store storage;
do{
storage.first();
return(0);
}while(x=1);
};
//------------------------------------
void books::first(void) {
//do {
system("cls");
cout<<"***********************************************************\n";
cout<<"***********************************************************\n";
cout<<"*****************Welcome to the Book***********************\n";
cout<<"***********************Database****************************\n";
cout<<"***********************************************************\n";
cout<<"***********************************************************\n\n\n\n";
cout<<" What would you like to do? \n";
cout<<" Select:\n\n";
cout<<" A To add a book to the database\n";
cout<<" F To search for a book\n";
cout<<" R To remove a book\n";
cout<<" C Clear book database\n";
cout<<" S Show all books\n";
cout<<" Q Quit program\n";
choice=getchar();
choice=toupper(choice);
switch(choice) {
case 'A': {
cout<<"you selected 'Add'\n";
enter(i);
break;}
case 'F': {
cout<<"you selected 'Search'\n";
break;}
case 'R': {
cout<<"you selected 'Remove'\n";
break;}
case 'C': {
cout<<"you selected 'Clear'\n";
break;}
case 'S': {
cout<<"you selected 'show all'\n";
list();
break;}
case 'Q': {
cout<<"you selected 'Quit'\n";
break;}
};
//}while(choice!='Q','A');
};
//---------------------------------------
//member functions
void books::enter(int i) {
cout<<"Enter the book title: ";
cin>>(np[i].title);
cout<<"Enter the author: ";
cin>>(np[i].author);
cout<<"Enter the ISBN number: ";
cin>>(np[i].isbn);
cout<<"Enter the publisher name: ";
cin>>(np[i].publishername);
cout<<"Is there a CDROM included (yes or no): ";
cin>>(np[i].cdrom);
cout<<"Year published: ";
cin>>(np[i].yearofpub);
cout<<"Enter price - exclude sign: ";
cin>>(np[i].price);
cout<<"\n\n\n information added to database\n\n\n";
system ("cls");
main(0);
};
void books::list(void) {
int i;
int ch;
for (i=0; i<2; i++) {
cout<<"title "<<np[i].title<<endl;}
main(0);
//cout<<"name "<<np[i].name<<
}
the problem is in the enter function. After the information has been entered the program calls main(int) again but then breaks from the program. Anyone know how i can stop this?
Code:
//---------------------------------------
//member functions
void books::enter(int i) {
cout<<"Enter the book title: ";
cin>>(np[i].title);
cout<<"Enter the author: ";
cin>>(np[i].author);
cout<<"Enter the ISBN number: ";
cin>>(np[i].isbn);
cout<<"Enter the publisher name: ";
cin>>(np[i].publishername);
cout<<"Is there a CDROM included (yes or no): ";
cin>>(np[i].cdrom);
cout<<"Year published: ";
cin>>(np[i].yearofpub);
cout<<"Enter price - exclude sign: ";
cin>>(np[i].price);
cout<<"\n\n\n information added to database\n\n\n";
system ("cls");
main(0);
};
I want to be able to access the menu system again after every function.
Cheers
Andy