im a new programmer and user here. I don't want to use goto in my code because I don't want to be called " a bad programmer". I need your experience to get rid of that.
#include <iostream>
#include <time.h>
using namespace std;
int main()
{
srand(time(NULL));
int control = 1;
char a[50], harf[5][10];
a[0] = 65 + rand() % 26;
for (int i = 1; i < 50; i++)
{
if (i % 2 == 0)
a[i] = 65 + rand() % 26;
else
a[i] = 97 + rand() % 26;
come:
for (int j = 0; j < i; j++)
{
if (a[i] == a[j])
{
if (i % 2 == 0)
{
a[i] = 65 + rand() % 26; goto come;
}
else
{
a[i] = 97 + rand() % 26; goto come;
}
}
else
continue;
}
cout << a[i]<<" ";
}
system("pause");
}
No need to create a function, replace your "goto" with "j = -1;"