Recursive output won't reset count.

My program keeps counting the permutations even after the second input.
Enter a string to permute ( to exit):
1) bac
2) bca
3) abc
4) acb
5) cba
6) cab
Enter a string to permute ( to exit):
7) gfedcba
8) gfedcab
9) gfedbca
10) gfedbac
11) gfedacb
12) gfedabc

It's suppoused to restart after the user eneter the second string. I've tried everything. Please lead me in the right direction. Might have to change my major I'm sure this has a simple solution.

#include <iostream>
#include <string>
using namespace std;

// FIXME: Use a static variable to count permutations. Why must it be static?

void PermuteString(string head, string tail) {
char current = '?';
string newPermute = "";
int len = 0;
int i = 0;

len = tail.length();


if (len <=1) {
// FIXME: Output the permutation count on each line too
static int count = 0;
{
count++;
cout<<count << ") ";


}
cout <<head + tail <<endl;

}
else {

// FIXME: Change the loop to output permutations in reverse order
for (int i=len-1; i>=0; i--) {
current = tail[i]; // Get next leading character
newPermute = tail.substr(0, i)+ tail.substr(i + 1);;
// Get the rest of the tail
PermuteString(head + current, newPermute);


}
}

return;
}

int main() {

const string PROMPT_STRING = "Enter a string to permute (<Enter> to exit): ";
string input = "";

// Get input and permute the string
cout << PROMPT_STRING << endl;
cin >> input;

while (input.length() > 0) {
PermuteString("", input);
cout << PROMPT_STRING << endl;
input = "";
cin >> input;
}
cout << "Done." << endl;

return 0;
}
Topic archived. No new replies allowed.