Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.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/8/xslt/3.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++中使用的彩票程序,我想知道这个代码能用来比较数字 do { for (int Num = 0; Num < 6; Num++) { if (RandomNumber[Num] == Numbers[Games][Num]) { cout << "A Number matches" << Numbers[Games][Num] << endl; } else { cout << "Bad Luck, Try Again Next Time" << Numbers[Games][Num] << endl; } } Games = Games - 1; } while (Games > -1); do { 对于(int Num=0;Num_C++_Arrays - Fatal编程技术网

如何在c+中比较一维数组和二维数组中的值+; 我正在创建一个在C++中使用的彩票程序,我想知道这个代码能用来比较数字 do { for (int Num = 0; Num < 6; Num++) { if (RandomNumber[Num] == Numbers[Games][Num]) { cout << "A Number matches" << Numbers[Games][Num] << endl; } else { cout << "Bad Luck, Try Again Next Time" << Numbers[Games][Num] << endl; } } Games = Games - 1; } while (Games > -1); do { 对于(int Num=0;Num

如何在c+中比较一维数组和二维数组中的值+; 我正在创建一个在C++中使用的彩票程序,我想知道这个代码能用来比较数字 do { for (int Num = 0; Num < 6; Num++) { if (RandomNumber[Num] == Numbers[Games][Num]) { cout << "A Number matches" << Numbers[Games][Num] << endl; } else { cout << "Bad Luck, Try Again Next Time" << Numbers[Games][Num] << endl; } } Games = Games - 1; } while (Games > -1); do { 对于(int Num=0;Num,c++,arrays,C++,Arrays,我认为你应该检查所有数字[游戏],不仅仅是数字[游戏][Num],我只是猜测。我不知道你的全部想法。我认为你应该这样做: do { for (int Num=0; Num<6; Num++) { bool exist = false; for( int i = 0; i < 6; ++i ) { if (RandomNumber[Num] == Numbers[Games][i]) exist

我认为你应该检查所有数字[游戏],不仅仅是数字[游戏][Num],我只是猜测。我不知道你的全部想法。我认为你应该这样做:

do
{
    for (int Num=0; Num<6; Num++)
    {
        bool exist = false;
        for( int i = 0; i < 6; ++i ) 
        {
             if (RandomNumber[Num] == Numbers[Games][i]) exist = true;
        }
        if (exist)           
        {
            cout<<"A Number matches"<<RandomNumber[Num]<<endl;
        }
        else
        {
           cout<<"Bad Luck, Try Again Next Time"<<RandomNumber[Num]<<endl;
        }
    }
    Games = Games - 1;
}
while (Games>-1);
}
do
{

对于(int Num=0;Num假设您试图匹配整行,那么您当前的逻辑似乎不是很好。
这是@Adam Folwarczny发布的内容的稍微修改版本

#include <iostream>

int main (void)
{
    int Numbers [] [6] = 
    {
        {1, 2, 3, 4, 5, 6},
        {7, 8, 9, 10, 11, 12},
        {13, 14, 15, 16, 17, 18},
        {19, 20, 21, 22, 23, 24}
    };

    int RandomNumber [] = {13, 14, 15, 16, 17, 18} ;

    int nGames = sizeof (Numbers) / sizeof (Numbers [0]) ;
    int nNumbers = sizeof (RandomNumber) / sizeof (RandomNumber [0]) ;

    // This assumes order matters.
    for (int i = 0; i < nGames; ++i) {

        bool bWin = true ;

        for (int j = 0; j < nNumbers; ++j) {
            if (RandomNumber [j] != Numbers [i] [j]) {
                bWin = false ;
                break ;
            }
        }

        if (bWin == true) {
            std::cout << "Player " << (i + 1) << " won!" << std::endl ;
        }

        else {
            std::cout << "Player " << (i + 1) << " lost!" << std::endl ;
        }
    }

    return 0 ;
}
#包括
内部主(空)
{
整数[][6]=
{
{1, 2, 3, 4, 5, 6},
{7, 8, 9, 10, 11, 12},
{13, 14, 15, 16, 17, 18},
{19, 20, 21, 22, 23, 24}
};
int RandomNumber[]={13,14,15,16,17,18};
int nGames=sizeof(数字)/sizeof(数字[0]);
int nNumbers=sizeof(RandomNumber)/sizeof(RandomNumber[0]);
//这意味着秩序问题。
对于(int i=0;istd::你试过调试吗?在所有代码运行时都尝试过调试,但是没有完全达到我的目的,因为它说没有匹配项,即使有匹配的数字ADD
std::试着将
Games=Games-1
移动到for-loop之外。你的缩进真的很奇怪。我认为他的while循环已经在游戏中迭代了。。。所以不需要额外的循环。我不认为。如果他想检查数组数字[Games]中是否存在数字RandomNumber[num],那么他需要迭代数组数字[Games]中的所有数字.我正在尝试创建一个彩票程序,所以我想要比较的是检查随机数数组中的一个数字是否与作为玩家输入程序的数字2d数组中的任何一个数字匹配