I dont really know if this is right or not, I'm still learning C++ but I think I can help at this problem of yours. I had experience in programming other languages and I hope it helps...
I actually debugged you code. It wasn't really the program's error but a LOGICAL ERROR - that is, the syntax is right, the compiler says it is right, but what it does is "wrong". Still with me?
My solution, I added the following line(s) to your code. Fortunately it worked. I hope this works...
char AbsorbKey[2];
cin.getline(AbsorbKey, 50);
I added them to the "void menu()" function. It now looks like this:
void menu() {
Book *storedBooks= new Book [20];
unsigned short int counter=1;
int exit=1;
while(exit) {
unsigned short int menuChoice;
cout << "\n\n ***Welcome to the Library of
E-Books***\n\n\n";
cout << " (1) View Sample Book Info\n";
cout << " (2) Store New Book Info\n";
cout << " (3) Search Book Info\n";
cout << " (4) Leave the Library\n\n\n";
cout << " Enter Choice #: ";
cin >> menuChoice;
// This is what I added =>
char AbsorbKey[2];
cin.getline(AbsorbKey, 50);
// :~
switch(menuChoice) {
//...
}//end switch(menuChoice)
delete [] storedBooks;
}//end while loop
}//end menu()
Explanation:
I don't really know how or why it happened. I arrived at this solution because when I was debugging it (without the lines I added), I noticed that the first byte of bAuthor always changes to "/00" or simply a empty character. And then, it would pass the cin.getline() and assumed that there was already input from the user.
A hunch - a character that cant be read by "cin >> int" was passed to "cin.getline(char[], int)". The function thought that it had already recieved the input it needed.
I dont think this is the right explanation. But I hope it works for you... It worked for me
__________________________________
www.edsamail.com
|