Alright I gave you the solution on how to do it but I figured I should break down your code and help you understand why yours does what it does.
Cleaned it up a little bit but left it, mostly, the same.
Code:
#include <iostream>
using namespace std;
char a('A'), b('B'), c('C'), d('D'), generator; // Initialize these outside of any scope so they're able to be used in every function.
int count2(0); // Initialize outside of any scope so they're able to be used in every function.
int incre(int a, int b, int c, int d, int count2 = 0)
{
switch (count2)
{
case 1:
a = a;
break;
case 2:
a = b;
break;
case 3:
b = c;
break;
default:
c = d;
}
return count2++;
}
int main()
{
generator = a;
for (int i = 0, count2 = 0; i < 4; i++)
{
incre(a, b, c, d, count2);
count2++;
cout << generator;
}
return 0;
}
Let's start from the top. You initially initialized each variable in the main scope, calling upon them and changing them in incre doesn't actually work, all you do when you call incre(a, b, c, d, count2); is pass the values of each of these variables, you aren't passing the variables themselves. Also, you make a second set of each of these variables in incre with the same names, it's not invalid but it's confusing. and
I don't even.... You're passing count2 in the for loop which doesn't even do anything (You don't define parameters, you just declare them). And you don't need to do count++ inside the for loop, you can do it right next to i++ the same way you initialized i and count2.
Now the biggest thing though is your switch. You don't actually modify any of the original variables, at all. It's always going to be A. What you can do, instead of setting a = a, you could return the char variable you passed into the function (which it will convert to char) or you could make the incre function char and return it that way. Also, you have it start at 1, 2, 3, default which means when you pass count2 as 0 it will go right to default and print D. (Remember, everything always starts at 0)
So, here's the new (simpler) code that will do what you want.
Code:
#include <iostream>
using namespace std;
char a('A'), b('B'), c('C'), d('D'), generator = a; // Initialize these outside of any scope so they're able to be used in every function.
// I removed count2 from here because it's being redefined in the for loop.
char incre(int a2, int b2, int c2, int d2, int count2)
{
switch (count2)
{
case (0) :
return a2;
break;
case (1):
return b2;
break;
case (2):
return c2;
break;
case (3):
return d2;
break;
default:
cout << "Something broke..." << endl;
return 1;
break;
}
}
int main()
{
for (int i = 0, count2 = 0; i < 4; i++, count2++)
{
generator = incre(a, b, c, d, count2);
cout << generator;
}
return 0;
}
(Also, if that post above using an ostream& function is too complicated, you can essentially just change print(cout, i) to cout << i and it will do the exact same thing.)