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回出力します。それを回避する方法は?入力した値を、ここに表示されていない「ブックの追加」オプションですでに追加した値と比較しています。