Hi,
Try to run this code:
It should work well the first time you input book details.Code:#include<iostream.h> #include<windows.h> #include<conio.h> //constants const int TMAX = 30; const int PMAX = 15; const int CMAX = 100; //class class books { private: char title[TMAX]; char publisher[PMAX]; double price; int quantity; public: void input() { cout<<"\n\n\t[ Title ] :: "<<flush; cin.get(title, TMAX); cin.ignore(10,'\n'); cout<<"\n\t[ Publisher ] :: "<<flush; cin.get(publisher, PMAX); cin.ignore(10,'\n'); cout<<"\n\t[ Price ] :: "; cin>>price; cout<<"\n\t[ Quantity ] :: "<<flush; cin>>quantity; } void output() { cout<<"\n\t[ Title ] :: "<<title<<endl; cout<<"\t[ Publisher ] :: "<<publisher<<endl; cout<<"\t[ Price ] :: "<<price<<endl; cout<<"\t[ Quantity ] :: "<<quantity<<endl<<flush; } void sell() { --quantity; } }; //main void main() { books book[CMAX]; int p = 0,j; int booknumber; char choice = 'x'; while (choice != 'q' && choice != 'Q') { system("CLS"); cout<<"\n\n\t:: [ BOOK STORE MENU ] ::"<<endl; cout<<"\n\t[ [A]dd Books ]"; cout<<"\n\t[ [D]isplay Books ]"; cout<<"\n\t[ [S]ell a Book ]"; cout<<"\n\t[ [Q]uit ]"; cout<<"\n\n\t::::[ ]::::\b\b\b\b\b\b"<<flush; choice = getche(); switch(choice) { case 'a': case 'A': system("CLS"); cout<<"\n\n\t:: Enter Data For Book "<<p+1<<" ::"<<endl; book[p++].input(); break; case 'd': case 'D': system("CLS"); for (j=0;j<p;j++) { cout<<"\n\n\t:: Data for Book "<<j+1<<" ::"<<endl; book[j].output(); } getch(); break; case 's': case 'S': system("CLS"); cout<<"\n\n\t:: Enter Book Number :: [ ]\b\b\b\b"; cin>>booknumber; book[booknumber-1].sell(); cout<<"\n\n\t:: New Data for Book "<<booknumber<<" ::"<<endl; book[booknumber-1].output(); getch(); case 'q': case 'Q': break; } } }
However, when you come to input the details for the second book, it skips the book title!![]()
Also, I haven't added conditional statements that will handle cases where the user inputs incorrect data, still have to code it![]()
Marc![]()



LinkBack URL
About LinkBacks



