[C++]Help in Yes or No loop

01/17/2016 15:49 FinalKnightx#1
Can someone please teach me how can I add a Yes or No loop in this program? This is a simple library system which will store 20 book titles with a maximum of 50 characters each. Every time after the user inputs a title, it will prompt for a yes or no. If the user inputs yes, it will ask for another title. if no, it will display the title of the books stored in the array.
Code:
#include <iostream>
using namespace std;

int main()
{
	char book[20][50],choice;
	int index;
	cout<< "ADDING BOOK - MMSU LIBRARY";
	for ( int i = 0; i < 20; i++ )
	{
		cout << "\n\nTitle: :";
		cin.getline(book[i], 50);
}
	system("cls");
				cout << "DISPLAY BOOK - MMSU Library System";
				cout << "\n\nBook Index" " \tTitle";
	for ( int i = 0; i < 20 ; i++ )
	{
		index=i+1;
		cout<<endl<<"    "<<index<<"\t\t"<<book[i]<<endl;
	}
	system("pause");
	return 0;
}
01/18/2016 07:18 IceTrailer#2
Quote:
Originally Posted by FinalKnightx View Post
Can someone please teach me how can I add a Yes or No loop in this program? This is a simple library system which will store 20 book titles with a maximum of 50 characters each. Every time after the user inputs a title, it will prompt for a yes or no. If the user inputs yes, it will ask for another title. if no, it will display the title of the books stored in the array.
Code:
#include <iostream>
using namespace std;

int main()
{
char book[20][50],choice;
int index;
cout<< "ADDING BOOK - MMSU LIBRARY";
for ( int i = 0; i < 20; i++ )
{
cout << "\n\nTitle: :";
cin.getline(book[i], 50);
}
system("cls");
cout << "DISPLAY BOOK - MMSU Library System";
cout << "\n\nBook Index" " \tTitle";
for ( int i = 0; i < 20 ; i++ )
{
index=i+1;
cout<<endl<<"    "<<index<<"\t\t"<<book[i]<<endl;
}
system("pause");
return 0;
}

bool done = false;

In the beginning of your for loop:
if (done) break;
Also i don't advise you to use a 2 dimensional array. Just use std:vector or sth