So I want to build a game using C++. Everything was fine until I met a problem.
The game was suppose to count the number of repeated and adjacent alphabets from some random alphabets but for some reason I would not get the function to word the output was suppose to be the total number of repeated numbers and adjacent numbers.
a = rand() % 7;
printf("%c", alphabet[a]);
beta[count] = beta[a];
Here is the code:
for (i = 0; i <=12; i++)
{
for (g = i + 1; g <= 12; g++)
{
if (beta[i] == beta[g])
{
repeated++;
}
i = g + 1;
if (beta[i] == beta[g])
{
adjacent++;
}
}
printf("\nnumber of repeated alphabets=%d\n", repeated);
printf("number of adjacent alphabets=%d\n", adjacent);
}
Let's say that the random generator generates C,B,A,A,B,D,G, the for loop is suppose to count the number of times a alphabet has repeated so A,A,B,B appear, so it should show that the number of repeated characters is 2 and the adjacent character is 1 but my current program out shows the number of repeated alphabets to be 6 and adjacent to be 1 so i have no idea will i is wrong with the problem
Should this be beta[count] = a;? Using beta[a] doesn't make sense here if this is initialization, since you haven't filled anything in the beta array yet.
EDIT: or maybe beta[count] = alphabet[a];? Depends what you want to actually be in the beta array.
because initially when i play the code the output will not show so i play around with the for loop and my friend told me if i add this i=g+1, it will work but so far its still not working
for my code i need the for loop to count the 7 alphabets that is store inside the beta array, and from there count how many repeated and adjacent alphabets are there
So you have an array, 'beta' which contains letters of the alphabet. And you want to check that array to see if 2 adjacent letters are the same.
So... ignore your code for now. Instead, how can you check to see if 2 letters (let's say, beta[0] and beta[1]) are the same? Can you show me the code for that?
IMO, you should stop trying to just find something that works. The best thing for you is to understand the problem. For that, I'm trying to break it down into smaller parts.
So... let's start small. You have 2 letters, beta[0] and beta[1]. How can you see if they are the same?