用c++进行宾果测试
Bingo test with c++
我在没有代码的情况下测试了几年,做了一个迷你宾果测试。。。
最后,我得到了:
#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};
^^^^^^
相关文章:
- 使用C++库在Android项目中修改gradle中的cmake参数,用于插入指令的测试
- 无法编译 rtmidi 测试 cmidiin.cpp 文件, 非法指令
- 尽管测试成功,CppUnit测试核心仍被丢弃.为什么
- 数据成员SFINAE的C++17测试:gcc vs clang
- 如何使用重载的相等(==)运算符向测试用例添加描述
- 为什么二进制搜索在我的测试中不起作用
- 从父数组测试用例构造二叉树失败
- 试图对缓存进行跨步测试,但程序并没有结束
- 有什么好的方法可以让系统调用代理允许在单元测试中进行模拟
- OpenGL在启用深度测试时不会丢弃我的碎片
- 为测试目标创建具有不同源文件夹的文件
- 在子目录中使用target_sources()命令时用于单元测试(qtest)的项目结构
- VC++本机单元测试,找不到调试符号
- 换位表导致测试失败(但在游戏中运行良好)
- 用于交叉编译和CMake的预处理器宏的单元测试
- 谷歌测试中的期望值存储在哪里
- 如何在for循环中包含两个索引值的测试条件
- 在cygwin中测试新的boost安装时出现cpp错误
- 使用rdtsc进行基准测试的缺点是什么
- 更正 CMakeList.txt 用于谷歌测试的文件?