Hello I am writing some code that takes a string of n letters, so a, or aa or aaa or aaaa...a and transforms these into d or dd or ddd or dddd...d by essentially counting. e.g aaaa -> aaab -> aaac -> aaad -> aaba and so on. Also technically the user inputs what the ending is whether it be d or e,f,g; however, for practical reasons counting up to dddd should work. My main issue is I am having trouble getting the letters correct. I get up to aadd and then once I go to abaa I have trouble getting the second to last a to switch correctly.

Code:
#include<iostream>
#include<string>
#include<vector>
using namespace std;

int main()
{
    vector<string> pleasework;
    string apple = "aaaaaa";
    int end = apple.size()-1;
    int counter = 1;
for(int j = 0; j < 25; j++)
{
    for (int i = 0; i < 3; i++)
    {
        apple[end] = (char)(apple[end]+1);
        cout << apple <<endl;
    }
    apple[end] = 'a';
    if(apple[end - counter]!= 'd')
    {
        apple[end - counter] = (char)(apple[end - counter]+1);
    }
    else
    {
        counter++;
    }
cout << apple <<endl;
}

}