Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/153.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/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
C++ Xcode 7';此处不允许函数定义';_C++_Arrays_Xcode_Loops - Fatal编程技术网

C++ Xcode 7';此处不允许函数定义';

C++ Xcode 7';此处不允许函数定义';,c++,arrays,xcode,loops,C++,Arrays,Xcode,Loops,我的代码如下。我尝试了所有不同的选择。我仍然通过课堂学习C++,但已经陷入僵局。Xcode表示错误出现在三条直线上。示例:**code*任何建议都会很好,并且会寻找更好地理解阵列的方法 #include <iostream> #include <string> #include <ctime> #include <cstdlib> using namespace std; int board [7] [7]; void initBoard (

我的代码如下。我尝试了所有不同的选择。我仍然通过课堂学习C++,但已经陷入僵局。Xcode表示错误出现在三条直线上。示例:**code*任何建议都会很好,并且会寻找更好地理解阵列的方法

#include <iostream>
#include <string>
#include <ctime>
#include <cstdlib>

using namespace std;

int board [7] [7];

void initBoard (int array1[7][7]) {
srand(time(0));
string position[7][7];
int moves = rand() % 8 + 5;
int r = 0;
int c = 0;
for (c = 0; c < 7; c++) {
    if (c == 0 || c == 6) {
        for (r = 0; r < 7; r++) {
            position[r][c] = "  ";
        }
    }
    else {
        for (r = 0; r < 7; r++) {
            if (r == 0 || r == 6) {
                position[r][c] = "  ";
            }
            else {
                position[r][c] = "_ ";
            }
        }
    }
}

***void plantBombs (int array2[7][7]) {***
r = 0;
c = 0;
int k = (rand() % 5) + 1;
int d = ((rand() % 111) % 5) + 1;
int numBombs = rand() % 4 + 3;
int bombR[numBombs];
int bombC[numBombs];
int i = 0;
while (i < numBombs){
    bombR[i] = (rand() % 71) % 5 + 1;
    bombC[i] = (rand() % 123) % 5 + 1;
    while (bombR[i] == k && bombC[i] == d) {
        bombR[i] = (rand() % 97) % 5 + 1;
        bombC[i] = (rand() % 79) % 5 + 1;
    }
    while ((i > 0) && (bombR[i-1] == bombR[i]) && (bombC[i-1] == bombC[i])){
        bombR[i] = (rand() % 213) % 5 + 1;
        bombC[i] = (rand() % 857) % 5 + 1;
    }
    position[bombR[i]][bombC[i]] = "* ";
    i = i + 1;
}

不匹配的大括号。我在代码< >代码>插件板< /代码>中计算8代码< { <代码> 7代码> } />代码>不要仅仅因为它们以相同的字母开始添加标签。C++作为一个三星级程序员也不是恭维。也不要在可以避免的地方使用
***void
!我使用星星只是为了显示错误出现的地方。我本打算突出显示或加粗,但没有清晰地显示出来。谢谢你的帮助和建议。
***void placeYou (int array2[7][7]){***
    position[k][d] = "U ";
}

***void movePlayer (int arrary3[7][7]){***
    while (moves != 0) {
        cout << "SURVIVE " << moves << " MORE MOVES!" << endl;
        for (c = 0; c < 7; c++) {
            for (r = 0; r < 7; r++) {
                cout << position[r][c];
            }
            cout << endl;
        }
        cout << "Enter direction (N/S/E/W): ";
        string direction;
        cin >> direction;
        //if (direction == "N")
        if (direction == "N"){
            if (position[k][d-1] == "  "){
                cout << "You fell off the board" << endl;
                cout << "***YOU LOSE***" << endl;
                break;
            }
            else if (position[k][d-1] == "* "){
                cout << "BANG! YOUR DEAD!" << endl;
                cout << "***YOU LOSE!***";
                break;
            }
            else {
                position[k][d] = "* ";
                position[k][d-1] = "U ";
                d = d - 1;
            }
        }

        if (direction == "E"){
            if (position[k+1][d] == "  "){
                cout << "You fell off the board" << endl;
                cout << "***YOU LOSE***" << endl;
                break;
            }
            else if (position[k+1][d] == "* "){
                cout << "BANG! YOUR DEAD!" << endl;
                cout << "***YOU LOSE!***";
                break;
            }
            else {
                position[k][d] = "* ";
                position[k+1][d] = "U ";
                k = k + 1;
            }
        }

        if (direction == "S"){
            if (position[k][d+1] == "  ") {
                cout << "You fell off the board" << endl;
                cout << "***YOU LOSE***" << endl;
                break;
            }
            else if (position[k][d+1] == "* "){
                cout << "BANG! YOUR DEAD!" << endl;
                cout << "***YOU LOSE!***";
                break;
            }
            else {
                position[k][d] = "* ";
                position[k][d+1] = "U ";
                d = d + 1;
            }
        }
        if (direction == "W"){
            if (position[k-1][d] == "  "){
                cout << "You fell off the board" << endl;
                cout << "***YOU LOSE***" << endl;
                break;
            }
            else if (position[k-1][d] == "* "){
                cout << "BANG! YOUR DEAD!" << endl;
                cout << "***YOU LOSE!***";
                break;
            }
            else {
                position[k][d] = "* ";
                position[k-1][d] = "U ";
                k = k - 1;
            }

            moves = moves - 1;
        }
        if (moves == 0){
            cout << "***YOU WIN***";
        }
        else {
            cout << "";
        }

    }
}
int main()
{
   initBoard(board);
    ***plantBombs(board);
    placeYou(board);
    movePlayer(board);***

    return 0;

}