[Dev-C++] need help using cin.getline()
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Julio L. <ju2...@ya...> - 2001-10-13 17:06:44
|
I cant seem to figure out why my program seems to skip
over the part where it is supposed to take input for
the author using cin.getline() and skips down to the
next cin.getline() for the title. Does anyone have any
suggestions, or comments? Here is the code (I used a
header file which i'll put first in addition to the
source file):
library2.hpp:
class Book
{
public:
Book(){}
Book(char bAuthor[], char bTitle[], unsigned short int
bPubDate)
{
strcpy(author,bAuthor);
strcpy(title,bTitle);
pubDate= bPubDate;
}
~Book(){}
void setAuthor(char
bAuthor[]){strcpy(author,bAuthor);}
void setTitle(char bTitle[]){strcpy(title,bTitle);}
void setPubDate(unsigned short int bPubDate){pubDate =
bPubDate;}
char* getAuthor(){return author;}
char* getTitle(){return title;}
unsigned short int getPubDate() const{return pubDate;}
private:
char author[50];
char title[50];
unsigned short int pubDate;
};
library.cpp:
#include <iostream.h>
#include <string.h>
#include <stdlib.h>
#include "library2.hpp"
void sampBook();
void menu();
void newBook(Book *rStoredBooks,unsigned short int
&rCounter);
void newBook(Book *rStoredBooks, unsigned short int
&rCounter)
{
if(rCounter<21)
{
while(true)
{
char bAuthor[50], bTitle[50], bChoice;
unsigned short int bPubDate;
cout << "\n\n***Store New Book Information***\n\n\n";
cout << "Book #" << rCounter << "\n\n\n";
cout << "Book Author: ";
cin.getline(bAuthor, 50);
rStoredBooks[rCounter-1].setAuthor(bAuthor);
cout << "\n\nBook Title: ";
cin.getline(bTitle, 50);
rStoredBooks[rCounter-1].setTitle(bTitle);
cout << "\n\nBook Publication Date: ";
cin >> bPubDate;
rStoredBooks[rCounter-1].setPubDate(bPubDate);
rCounter++;
cout << "\n\n\n";
cout << " Are there any more books?(Y/N) : ";
cin >> bChoice;
switch(bChoice)
{
case 'Y': //fall through
case 'y': continue;
break;
case 'N': //fall through
case 'n': system("PAUSE");
system("cls");
break;
} //end switch
break;
}
}
else
{
cerr << "\n\n\n***Sorry, too many books have already
been stored.***\n\n\n";
system("PAUSE");
}
}//end newBook()
void sampBook()
{
Book *sampleBook= new Book("Julio Lajara", "The
Library", 2002);
cout << "\n\n ***Sample Book Information***\n\n\n";
cout << "Author: " << sampleBook->getAuthor() <<
"\n\n";
cout << "Title: " << sampleBook->getTitle() << "\n\n";
cout << "Publication Date: " <<
sampleBook->getPubDate() << "\n\n\n";
delete sampleBook;
system("PAUSE");
system("cls");
}//end sampBook()
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;
switch(menuChoice)
{
case 1: system("cls");
sampBook();
break;
case 2: system("cls");
newBook(storedBooks, counter);
break;
/* case 3: system("cls");
searchBook();
break; */
case 4: exit=0;
break;
default: system("cls");
continue;
break;
}//end switch(menuChoice)
delete [] storedBooks;
}//end while loop
}//end menu()
int main()
{
menu();
return 0;
}//end main()
=====
Julio
__________________________________________________
Do You Yahoo!?
Make a great connection at Yahoo! Personals.
http://personals.yahoo.com
|