Organise your program so that main() calls another function which you can then call again from anywhere else e.g.
#include <iostream>
#include <string>
using namespace std;
int aFunction()
{
int number;
tryagain:
cout<<"How many tablets are you starting with ? ";
cin>>number;
if(number>0 && number<=10000)
{
tabletfind(number);
}
else {cout<<"Number of Tablets must be greater than 0 and no more than 10000"<<endl;
goto tryagain;
}
return 0;
}
int tabletfind(int x)
{
if(x%2==0)
{
cout<<"Searching for a solution within 21 moves..."<<endl;
cout<<"No solution found within 21 moves. Sorry."<<endl;
string ans;
cout<<"Would you like to try again [Y/N]?";
cin>>ans;
if(ans=="y" || ans=="Y")
{
x = AFunction() }
else if (ans=="n" || ans=="N")
{
exit;
}
}
}
int main()
{
int number;
number = aFunction();
}
Please note I have not tested any of the above and I may have let a tear fall from my eye as I copied the goto.