boolean not working

https://gist.github.com/anonymous/ea835a51eb4dbe21bd37

focusing on 'bool checkIfCorrect function and main, ignore the rest

I'm trying to get CheckIfCorrect run and see if there are matches with the compcards[](five random numbers) array which I generated with another function.

Checkifcorrect only works if you guess right the first time other than that It doesn't work. Could anyone help?
1
2
3
4
5
6
7
8
9
10
11
bool checkIfCorrect(int checkcard, int compcards[], int player[]){

    for (int i=0; i<5; i++)
    {
        if(compcards[i] == checkcard)
        
        cout<<"correct"<< endl;
        return true; //You return true here on every loop    
    }
    return false;
}


I think what you intended on doing was have lines 7 and 8 inside of the if statement. Otherwise the function will return true regardless:
1
2
3
4
5
if(compcards[i] == check card)
{
    cout << "correct" << endl;
    return true;
}
thank you
Topic archived. No new replies allowed.