-
December 2nd, 2008, 10:52 PM
#1
Array Problem
This program prompts for ISBN title, author first name, author last name, and topics (up to 5) and should be able to handle up to 10000 books. An ISBN is a number that uniquely identifies a book. Assume all ISBNs are composed of exactly 10 digits. IF the ISBN is not already in the book array, the program adds the new book to the book array. If the given ISBN already exists, an error message is displayed. Either way, the main menu is displayed immediately afterwards.
I finished most of this function, but I cannot figure out how to compare the ISBN numbers or an efficient way to input them. If anyone can help me with this or has any other tips or advice, I would be very grateful.
Here is my code:
void Add_Book(Book& book){
char Add_Next_Book;
int Topic_Num, Book_Counter;
float Temp_Score;
float isbn[10];
long int Book_Number[10000];
do{
cout << "Enter Book Information" << endl;
cout << "ISBN:";
for(int i = 0; i < 10; i++){
cin >> isbn[i];
}
for(int i = 0; i < 10; i++){
Temp_Score = Temp_Score + (isbn[i] * pow(10.0 , 9 - i));
}
Book_Number[Book_Counter] = Temp_Score;
cout << "Title:";
cin >> book.Title;
cout << "First Name:";
cin >> book.First_Name;
cout << "Last Name:";
cin >> book.Last_Name;
do{
cout << "Number of topics:";
cin >> Topic_Num;
}while(Topic_Num < 0 && Topic_Num > 5);
for (int i = 1; i <= Topic_Num; i++){
cout << "Topic " << i << ":";
switch(i){
case 1:
cin >> book.Topic_One;
case 2:
cin >> book.Topic_Two;
case 3:
cin >> book.Topic_Three;
case 4:
cin >> book.Topic_Four;
case 5:
cin >> book.Topic_Five;
}
}
do{
cout << " Do you want to add another book?";
cin >> Add_Next_Book;
}while (Add_Next_Book != 'y' && Add_Next_Book != 'n');
Book_Counter++;
}while(Add_Next_Book != 'y');
}
-
December 2nd, 2008, 11:37 PM
#2
Re: Array Problem
Please use code tags and cut and paste code from your compiler between the tags. Read the board FAQ. Code tags preserve indentation and use a non-proportional font, it makes things much clearer.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|