尝试使用 1d 和 2d 数组为 CS 的分配制作掷骰子并遇到问题
到目前为止我所拥有的是这个(是的,我知道布尔结构很糟糕):
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <iomanip>
using namespace std;
int main()
{
int g[5][5] = {{}};
int d[11] = {};
int die1;
int die2;
srand(time(0));
for ( int roll = 1; roll <= 36000; ++roll )
{
die1 = 1 + rand() % 6;
die2 = 1 + rand() % 6;
if (die1 == 1 && (die2 == 1))
g[0][0] += 1;
if (die1 == 1 && die2 == 2)
g[0][1] += 1;
if (die1 == 1 && die2 == 3)
g[0][2] += 1;
if (die1 == 1 && die2 == 4)
g[0][3] += 1;
if (die1 == 1 && die2 == 5)
g[0][4] += 1;
if (die1 == 1 && die2 == 6)
g[0][5] += 1;
if (die1 == 2 && die2 == 1)
g[1][0] += 1;
if (die1 == 2 && die2 == 2)
g[1][1] += 1;
if (die1 == 2 && die2 == 3)
g[1][2] += 1;
if (die1 == 2 && die2 == 4)
g[1][3] += 1;
if (die1 == 2 && die2 == 5)
g[1][4] += 1;
if (die1 == 2 && die2 == 6)
g[1][5] += 1;
if (die1 == 3 && die2 == 1)
g[2][0] += 1;
if (die1 == 3 && die2 == 2)
g[2][1] += 1;
if (die1 == 3 && die2 == 3)
g[2][2] += 1;
if (die1 == 3 && die2 == 4)
g[2][3] += 1;
if (die1 == 3 && die2 == 5)
g[2][4] += 1;
if (die1 == 3 && die2 == 6)
g[2][5] += 1;
if (die1 == 4 && die2 == 1)
g[3][0] += 1;
if (die1 == 4 && die2 == 2)
g[3][1] += 1;
if (die1 == 4 && die2 == 3)
g[3][2] += 1;
if (die1 == 4 && die2 == 4)
g[3][3] += 1;
if (die1 == 4 && die2 == 5)
g[3][4] += 1;
if (die1 == 4 && die2 == 6)
g[3][5] += 1;
if (die1 == 5 && die2 == 1)
g[4][0] += 1;
if (die1 == 5 && die2 == 2)
g[4][1] += 1;
if (die1 == 5 && die2 == 3)
g[4][2] += 1;
if (die1 == 5 && die2 == 4)
g[4][3] += 1;
if (die1 == 5 && die2 == 5)
g[4][4] += 1;
if (die1 == 5 && die2 == 6)
g[4][5] += 1;
if (die1 == 6 && die2 == 1)
g[5][0] += 1;
if (die1 == 6 && die2 == 2)
g[5][1] += 1;
if (die1 == 6 && die2 == 3)
g[5][2] += 1;
if (die1 == 6 && die2 == 4)
g[5][3] += 1;
if (die1 == 6 && die2 == 5)
g[5][4] += 1;
if (die1 == 6 && die2 == 6)
g[5][5] += 1;
}
d[1] = g[0][0];
d[2] = g[1][0] + g[0][1];
d[3] = g[2][0] + g[0][2] + g[1][1];
d[4] = g[3]{0} + g[0][3] + g[1][2] + g[2][1];
d[5] = g[4][0] + g[0][4] + g[2][2] + g[3][1] + g[1][3];
d[6] = g[5][0] + g[0][5] + g[4][1] + g[1][4] + g[3][2] + g[2][3];
尝试使用 gnu 进行编译,并在底部开始 d[4] = ... 时出现此错误。
error: invalid conversion from int* to int [-fpermissive]
任何帮助将不胜感激,我真的需要完成这项任务......谢谢