Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/151.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 布尔函数不工作_C++_Arrays_Function_Boolean - Fatal编程技术网

C++ 布尔函数不工作

C++ 布尔函数不工作,c++,arrays,function,boolean,C++,Arrays,Function,Boolean,我想知道这个逻辑是否正确。该函数通过compcards[]获得一个数组,比如1,2,3,4,5,以及一个用户输入的数字,如4。然而,如果用户猜测,让我们假设6,它将返回false。我想让用户猜五次存储在compcards[]中的数字。我想知道我的if-else语句在这种情况下是否有意义 bool checkIfCorrect(int checkcard, int compcards[]){ for ( int i=0; i<5; i++) { if(comp

我想知道这个逻辑是否正确。该函数通过compcards[]获得一个数组,比如1,2,3,4,5,以及一个用户输入的数字,如4。然而,如果用户猜测,让我们假设6,它将返回false。我想让用户猜五次存储在compcards[]中的数字。我想知道我的if-else语句在这种情况下是否有意义

bool checkIfCorrect(int checkcard, int compcards[]){
    for ( int i=0; i<5; i++)
    {
        if(compcards[i] == checkcard)
            cout<<"correct"<< endl;
        return true;    
    }
    return false;
}
bool checkIfCorrect(int checkcard,int compcards[]){

对于(int i=0;i更改函数,如下所示

bool checkIfCorrect(int checkcard, int compcards[]){
    for ( int i=0; i<5; i++)
    {
        if(compcards[i] == checkcard)
        {       
            cout<<"correct"<< endl;
            return true;    
        }
    }
    return false;
}
bool checkIfCorrect(int checkcard,int compcards[]){

对于(int i=0;iI)而言,只能从函数返回一个值或在屏幕上打印一些内容,请避免同时执行这两项操作。对不起,我不是很清楚。数组“compcards”的用途是什么?它包含什么?用户输入或正确答案?这可能也很有用