In the above program, the main loop loops through once successfully, but on subsequent times it's as if the cin calls in the different getData() functions don't exist. It cout's the correct text (Inupt title:, Input price, etc.) but it never allows the user to cin the data; it just moves on to the next cout.Code:#include <iostream> #include <conio.h> using namespace std; class publication { protected: char title[20]; float price; public: publication() : price(0.0) { title[0] = '\0'; } virtual void getData() { cout<<"\nInput title: "; cin.get(title, 20); cout<<"\nInput price: "; cin>> price; } virtual void putData() { cout<<"\nTitle: "<< title; cout<<"\nPrice: "<< price; } }; class book : public publication { private: int pages; public: book() : publication(), pages(0) { } void getData() { publication::getData(); cout<<"\nInput pages: "; cin>> pages; } void putData() { publication::putData(); cout<<"\nPages: "<< pages; } }; class tape : public publication { private: int minutes; public: tape() : publication(), minutes(0) { } void getData() { publication::getData(); cout<<"\nInput minutes: "; cin>> minutes; } void putData() { publication::putData(); cout<<"\nMinutes: "<< minutes; } }; int main() { publication* ptr[10]; int pubs = 0; int i; do { if (pubs < 10) { cout<<"\nChoose between a book or tape (b/t): "; if (_getche() == 'b') ptr[pubs] = new book; else ptr[pubs] = new tape; ptr[pubs]->getData(); pubs++; cout<<"\nInput another? (y/n): "; } else { cout<<"\nSorry, out of room."; break; } } while(_getch() == 'y'); for (i = 0; i < pubs; i++) { ptr[i]->putData(); } cout<<"\n\n"; system("Pause"); for (i = 0; i < pubs; i++) { delete ptr[i]; } return 0; }
Any ideas why this is happening?