用c++进行宾果测试

Bingo test with c++

本文关键字:测试 c++      更新时间:2023-10-16

我在没有代码的情况下测试了几年,做了一个迷你宾果测试。。。

最后,我得到了:

#include <iostream>
using namespace std;
int main()
{
 int cartela[5][3] = { {1, 2, 3}, {6,7,8}, {11,12,13}, {14,15,16}, {17,18,19} } ;
 int sorteado[8];
 int detectado[5];
 cout << "Insira os 8 numeros sorteados: ";
 cin >> sorteado[0] >> sorteado[1] >> sorteado[2] >> sorteado[3] >> sorteado[4] >> sorteado[5] >>sorteado[6] >> sorteado[7];
for (int tsort=0; tsort<9; tsort++) {
    for (int i=0; i<6; i++) {
        for (int j=0; j<4; j++) {
        if (cartela[i][j] == sorteado[tsort])  {
                  detectado[i]++;
                                    }
    }
}
}
cout << "cartela 1: " << detectado[0]<<"n";
cout << "cartela 2: " << detectado[1]<<"n";
cout << "cartela 3: " << detectado[2]<<"n";
cout << "cartela 4: " << detectado[3]<<"n";
cout << "cartela 5: " << detectado[4]<<"n";
return 0;
}

或pastebin:http://pastebin.com/TLYAZTtE

如果你注意到,目标是获得用户在挂载游戏中键入的数字数量(卡特尔[5][3])。

而且,只有在第二场和第三场比赛中才能得出结果。在其他方面,结果令人难以置信。LOL

有人可以帮我找出我的错误是什么?

谢谢!

您的索引是错误的。例如,看看这个:

int sorteado[8];

即8个值的索引,但在for循环中:

for (int tsort=0; tsort<9; tsort++)

您正在循环从0到8的9个元素。纠正:

for (int tsort=0; tsort< 8; tsort++) {
    for (int i=0; i< 5; i++) {
        for (int j=0; j< 3; j++) {
        if (cartela[i][j] == sorteado[tsort])  {
              detectado[i]++
        }
}

}

现在,真的,你的问题是什么?

更新

您忘记初始化"detectado",因此,请将代码更新为:

int detectado[5] = {0};
                ^^^^^^