case 4:
{
string bookTitleDel;
int bookPageNDel;
int bookReviewDel;
float bookPriceDel;
cout << "\nPlease Enter the Title to be Deleted: ";
cin >> bookTitleDel;
cout << "\nTotal Number of Pages of the Book to be Deleted: ";
cin >> bookPageNDel;
cout << "\nPlease Enter Rating (stars): ";
cin >> bookReviewDel;
cout << "\nPlease Enter Price: ";
cin >> bookPriceDel;
for(int i=0;i<MAX_BOOKS;i++)
{
if((books[i].bookTitle!=bookTitleDel) && (books[i].bookPageN!=bookPageNDel) && (books[i].bookReview!=bookReviewDel) && (books[i].bookPrice!=bookPriceDel))
{
cout<<"\n\nBook Doesnt Exist\n";
continue;
}
}
for(int i=0; i<MAX_BOOKS; i++)
{
if((books[i].bookTitle==bookTitleDel) && (books[i].bookPageN==bookPageNDel) && (books[i].bookReview==bookReviewDel) && (books[i].bookPrice==bookPriceDel))
{
a=i;
books[i]= {};
cout << "\nBook Deleted\n";
for(int k=a; k<MAX_BOOKS-1; k++)
{
books[k]=books[k+1];
}
break;
}
}
break; //break to exit switch case #4.
如果不存在,此代码将打印 10 次“书不存在”。如何避免?我正在将输入的值与我已经使用此处未显示的“添加书”选项添加的值进行比较。