I couldn't think of a good title for the thread, hence the really bad one, sorry...
I'm currently working on a "tiny" game to learn some of the basics in C. In short, the computer makes an array of four randomly generated numbers between 0 and 9, then you try to guess what those four numbers are by making your own array of 4 numbers between 0 and 9.
What im doing right now is creating a sort of hint system, which tells you which of your four numbers are wrong, which ones are right but in the wrong position and which ones are completely wrong.
If the number is right, you get an 'R', if it is right but in the wrong position you get an 'S', and if its completely wrong you get an '_'...
Here's what i've done so far, im not copying all of the code, just the part i need help with, but could copy it all if its needed...
I'm guessing this is a rather simple task, but im having problems with the logic...Code:for(i=0; i<ARR_SIZE; i++)
{
if (guess[i] == secretNumber[i] && help[i] != 'S')
help[i] = 'R';
for(j=0; j<=i-1; j++)
{
if(guess[i] == secretNumber[j])
{
help[i] = 'S';
}
}
if (help[i] != 'R' && help[i] != 'S')
help[i] = '_';
}
printf("help: ", help[i]);
for(i=0; i<ARR_SIZE; i++)
{
printf("%c ", help[i]);
}