Problem in Looping back to Start

now I'm Having problem in repeating the loop after it finished doing the first and i want to try it again without exiting the program? I've been using while loop to do it but still no joy. so i decided to do the if statement. But the Array only accept 4 strings then it exit. Any one who can help? TIA.


#include "stdafx.h"
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>


using namespace std;


template <typename T>
void GetContents(T& Input);

template <typename T>
void DisplayContents(const T& Input);

int main()
{
int PASS = 0;
// To Display the unsorted and sorted Book Titles
std::vector<std::string> books;

GetContents(books);

std::cout << "\nMy original library (number of books: " << books.size() << "):\n\n";
DisplayContents(books);

std::sort(books.begin(), books.end());

std::cout << "\nMy sorted library (number of books: " << books.size() << "):\n\n";
DisplayContents(books);

std::cout << "Press 1 to try again, else to quit: ";
std::cin >> PASS;
std::cout << "\n";
if (PASS == 1)
{
GetContents(books);
}
else
{
return 0;
}

// to input All book titles
template <typename T>
void GetContents(T& Input)
{

const int MAX = 5;
string bookName;

std::cout << "Enter a Book Titles:\n> ";
for (int i = 0; i < MAX; i++)
{
std::getline(std::cin, bookName);
Input.push_back(bookName);
std::cout <<">";
}


}

//Display All input book titles
template <typename T>
void DisplayContents(const T& Input)
{

for (auto iElement : Input)
{
std::cout << iElement << '\n';
}
std::cout << '\n';

system("pause");
}
Last edited on
you can wrap all of main in a
bool done = false;
while(!done)
{
everything;
ask user if done, set done true/false...
}

Topic archived. No new replies allowed.