0

i have problem that the the loop to check if a digit is correct but not at the right place.
then print.

void feedback( char random[4], char guess[5])
{
    int i;

    for(i=0; i<4; i++)
    {
        if(guess[i]==random[i])
        {
            printf("#");
        }
    }


        if((guess[0]==random[1]||guess[0]==random[2]||guess[0]==random[3])&&guess[0]!=random[0])
        {
            printf("*");
        }
        if((guess[1]==random[0]||guess[1]==random[2]||guess[1]==random[3])&&guess[1]!=random[1])
        {
            printf("*");
        }
        if((guess[2]==random[0]||guess[2]==random[1]||guess[2]==random[3])&&guess[2]!=random[2])
        {
            printf("*");
        }
        if((guess[3]==random[0]||guess[3]==random[1]||guess[3]==random[2])&&guess[3]!=random[3])
        {
            printf("*");
        }
        printf("\n");

}

how to make sure the same digit is not used twice?

Edited by pyTony: Incorrect forum, moved

3
Contributors
2
Replies
4
Views
5 Years
Discussion Span
Last Post by WaltP
0

Do a for loop checking each number of guess with numbers after it and give error or do not accept guess, if you find same ones.

0

how to make sure the same digit is not used twice?

If you use it once, remove it from the list.

For example:

for(i=0; i<4; i++)
{
    if(guess[i]==random[i])
    {
        printf("#");
        guess[i] = -1;  // remove the guess since it's been used
    }
}

Edited by WaltP

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.