I want to create .h file to loop a program

Hello,

What I want to create is a file that I can Include in programs I create in the future.
The purpose of the program is to be a function that with minimal code in the new program I can run to loop the entire program with a prompt like:
"Do you want to run again(y/n)?"

I don't care if it is yes or no. That is just an idea of what I want it to do.

I have tried several things but can figure it out.

Any help would be appreciated.

Thank you for any ideas or suggestions in advance.
If you give me code to do this, please explain how it works.
Last edited on
If you want to loop your program just create a driver function for you program and the do-while loop it.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <string>

using namespace std;

int main()
{
	string answer;
	do
	{
		cout << "Would you like to start the program? (Yes or No)" << endl;
		cin >> answer;
		if (answer == "No"){ break; }
		else { driver(); } // Else run the driver
	
	} while (answer == "Yes");

	return 0;
}


You don't necessarily have to use a driver, but you can loop whatever function you want to run. A driver is nice because it will just keep looping your whole program while the answer remains "Yes". Once the answer is "No" it will break out of the loop and return 0;
Last edited on
Topic archived. No new replies allowed.