What happens if a DO WHILE statement doesn't meet its conditions?

I wrote a program and a small section of it contains a do while statement, it is supposed to search a file for matching strings then grab that information and output it to the user. It works and all but i intentionally put a wrong string for it to search for which it wont find, when it doesn't find the matching string it just makes a new line and stays blank. I'm wondering if it is possible to have like an ELSE for it so i can put an error message or something.
Here is the code if needed:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
void books::searchbook()
{
	ifstream book;
	book.open("books.txt",ios::in);

	char titlesearch[40],authorsearch[20];
	int found=0;
	cout<<"\nEnter title of book to search for: ";
	cin>>titlesearch;
	cout<<"Enter author of book: ";
	cin>>authorsearch;

	do
	{
		book>>add[i].author>>add[i].title>>add[i].price>>add[i].publisher>>add[i].stock;
	} 
	while (strcmp (titlesearch,add[i].title) != 0);
	while (strcmp (authorsearch,add[i].author) != 0);
	{
		found=1;
		cout<<"\nFOUND:-";
		cout<<"\nBook title is:\t"<<add[i].title;
		cout<<"\nAuthor name is:\t"<<add[i].author;
		cout<<"\nPublisher is:\t"<<add[i].publisher;
		cout<<"\nBook price is:\t"<<add[i].price;
		cout<<"\nBooks in stock:\t"<<add[i].stock<<endl;
	}
	book.close();
}
Last edited on
Topic archived. No new replies allowed.