如何修复C3861:'...':找不到标识符

时间:2019-06-02 13:24:33

标签: c++

我想使用Visual Studio创建一个游戏扫雷器。项目可视c ++ Win32控制台应用程序。源文件C ++文件(.cpp) 这是我的源代码

#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <conio.h>
#include <time.h>

int menu()//menampilkan menu
{
    int x;
    printf("\nThe Minesweeper for You\n\n");
    printf("<<Main Menu>>\n\n");
    printf("1.Start\n");
    printf("2.Exit\n\n");
    printf("Masukkan pilihan : ");
    scanf("%i", &x);
    while ((x<1) || (x>2))
    {
        printf("Pilihan Invalid !\n");
        printf("Masukkan pilihan : \n");
        scanf("%i", &x);
    }
    printf("\n");
    return x;
}

void cek(int board[15][15], int revealed[15][15], int x, int y)//mengecek saat board[x][y] berisi 0
{
    //Kamus lokal
    int i, j;
    revealed[x][y] = 1;

    //Algoritma
    for (i = x - 1; i<x + 2; i++)
    {
        for (j = y - 1; j<y + 2; j++)
        {
            if (i >= 0 && j >= 0 && i<15 && j<15)
            {
                if (revealed[i][j] == 0 && board[i][j] != 0)
                {
                    revealed[i][j] = 1;
                }
            }
        }
    }
    for (i = x - 1; i<x + 2; i++)
    {
        for (j = y - 1; j<y + 2; j++)
        {
            if (i >= 0 && j >= 0 && i<15 && j<15)
            {
                if (revealed[i][j] == 0 && board[i][j] == 0)
                {
                    cek(board, revealed, i, j);
                }
            }
        }
    }


}



int klik(int board[15][15], int revealed[15][15], char kondisi[15][15])
{
    //Kamus lokal
    int a, b, x, y, q, z;

    //Algoritma
    do {
        printf("X: ");
        scanf("%i", &y);
        printf("y: ");
        scanf("%i", &x);
    } while (x<1 || y<1 || x>15 || y>15);

    x--; y--;//konfersi ke matriks yg dari 0 sampai 14
    if (kondisi[x][y] == 'F')
    {
    }
    else if (board[x][y] == 9)
    {
        for (a = 0; a<15; a++)for (b = 0; b<15; b++)
        {
            if (board[a][b] == 9)revealed[a][b] = 1;
        }
        z = 1;

    }
    else if (board[x][y] == 0)
    {
        revealed[x][y] = 1; //revealed 1 terbuka
        cek(board, revealed, x, y);
    }
    else{ revealed[x][y] = 1; }

    for (a = 0; a<15; a++)
    {
        for (b = 0; b<15; b++)
        if (revealed[a][b] == 1)
        {
            switch (board[a][b])
            {
            case 0: kondisi[a][b] = '0'; break;
            case 1: kondisi[a][b] = '1'; break;
            case 2: kondisi[a][b] = '2'; break;
            case 3: kondisi[a][b] = '3'; break;
            case 4: kondisi[a][b] = '4'; break;
            case 5: kondisi[a][b] = '5'; break;
            case 6: kondisi[a][b] = '6'; break;
            case 7: kondisi[a][b] = '7'; break;
            case 8: kondisi[a][b] = '8'; break;
            case 9: kondisi[a][b] = '#'; break;
            }

        }

    }

    q = jumlhbuka(revealed, kondisi);

    if (z == 1){ return 1; }
    else if (q >= 200){ z = 2; }
    else{ z = 0; }
    return z;

}

int jumlhbuka(int revealed[15][15], char kondisi[15][15])
{
    int a, b, q = 0;
    for (a = 0; a<15; a++)
    {
        for (b = 0; b<15; b++)
        {
            if (revealed[a][b] == 1 && kondisi[a][b] != '#'){ q = q + 1; }
        }
    }
    return q;
}


void flag(char kondisi[15][15], int revealed[15][15])
{
    //Kamus lokal
    int x, y;
    //Algoritma
    do {
        printf("X: ");
        scanf("%i", &y);
        printf("y: ");
        scanf("%i", &x);
    } while (x<1 || y<1 || x>15 || y>15);
    if (revealed[x - 1][y - 1] == 0)//board = 0 tertutup
    {
        kondisi[x - 1][y - 1] = 'F';

    }
}

void rflag(char kondisi[15][15], int revealed[15][15])
{
    //Kamus lokal
    int x, y;

    //Algoritma
    do {
        printf("X: ");
        scanf("%i", &y);
        printf("y: ");
        scanf("%i", &x);
    } while (x<1 || y<1 || x>15 || y>15);

    if (kondisi[x - 1][y - 1] == 'F')       //jika kondisinya sedang flag
    {
        kondisi[x - 1][y - 1] = '_';
    }
}

void random(int A[15][15])
{
    //Kamus lokal
    srand((unsigned)time(NULL));
    int a, b, c = 0;

    //Algoritma
    for (a = 0; a<15; a++){ for (b = 0; b<15; b++){ A[a][b] = 0; } }
    while (c<25)
    {
        for (a = 0; a<15 && c<25; a++)
        {
            for (b = 0; b<15 && c<25; b++)
            {
                if (A[a][b] != 9)
                {
                    A[a][b] = rand() % 10;
                    if (A[a][b] == 9){ c++; }
                    else{ A[a][b] = 0; }
                }
            }
        }
    }
}


void PasangBom(int board[15][15])//mengisi board dengan 0-9. 9 maka berisi bom dan 0 maka kosong
{
    //Kamus lokal
    int x, y, a, i, j; a = 25;

    //Algoritma
    random(board);//isi board dengan 9 sebagai bom dan yang lain 0;
    for (x = 0; x<15; x++)
    for (y = 0; y<15; y++)
    if (board[y][x] == 9)
    {
        if ((y - 1) >= 0)
        if (board[y - 1][x] != 9)
            board[y - 1][x]++;
        if ((y - 1) >= 0 && (x - 1) >= 0)
        if (board[y - 1][x - 1] != 9)
            board[y - 1][x - 1]++;
        if ((x - 1) >= 0)
        if (board[y][x - 1] != 9)
            board[y][x - 1]++;
        if ((y + 1) < 15)
        if (board[y + 1][x] != 9)
            board[y + 1][x]++;
        if ((y + 1) < 15 && (x + 1) < 15)
        if (board[y + 1][x + 1] != 9)
            board[y + 1][x + 1]++;
        if ((x + 1) < 15)
        if (board[y][x + 1] != 9)
            board[y][x + 1]++;
        if ((y - 1) >= 0 && (x + 1) < 15)
        if (board[y - 1][x + 1] != 9)
            board[y - 1][x + 1]++;
        if ((y + 1) < 15 && (x - 1) >= 0)
        if (board[y + 1][x - 1] != 9)
            board[y + 1][x - 1]++;
    }

}



void Tampilkar(char x[15][15])
{
    //Kamus lokal
    int a = 0;
    int b = 0;

    //Algoritma
    printf(" y\\x");
    while (b<15)
    {
        if (b<9){ printf("_%i__", b + 1); }
        else{ printf("%i__", b + 1); }
        b = b + 1;
    }
    printf("\n");
    while (a<15)
    {
        b = 0;
        if (a<9){ printf(" %i", a + 1); }
        else{ printf("%i", a + 1); }
        while (b<15){ printf("_|_%c", x[a][b]); b = b + 1; }
        printf("_|\n");
        a = a + 1;
    }
    printf("\n");
}

void Tampilang(int x[15][15])
{
    //Kamus lokal
    int a = 0;
    int b = 0;

    //Algoritma
    printf(" y\\x");
    while (b<15)
    {
        if (b<9){ printf("_%i__", b + 1); }
        else{ printf("%i__", b + 1); }
        b = b + 1;
    }
    printf("\n");
    while (a<15)
    {
        b = 0;
        if (a<9){ printf(" %i", a + 1); }
        else{ printf("%i", a + 1); }
        while (b<15){ printf(" | %i", x[a][b]); b = b + 1; }
        printf(" |\n");
        a = a + 1;
    }
    printf("\n");
}

void start()
{
    //Kamus lokal
    int a, b, x, y, z, jbuka;
    int jk = 0;//jumlah klik,
    int dead = 0;//0 masih main, 1 kalah, 2 menang , 4 keluar(stop)
    int board[15][15];
    int revealed[15][15];
    char kondisi[15][15];

    //Algoritma
    PasangBom(board);
    for (a = 0; a<15; a++)for (b = 0; b<15; b++)revealed[a][b] = 0;//mengkosongkan parameter buka
    for (a = 0; a<15; a++)for (b = 0; b<15; b++)kondisi[a][b] = '_';//mengkosongkan tampilan awal
    Tampilkar(kondisi);
    while (dead == 0)
    {
        do{
            printf("1.Klik\n");
            printf("2.Flag\n");
            printf("3.Remove Flag\n");
            printf("4.Stop\n");
            printf("Masukkan pilihan : ");
            scanf("%i", &z);
        } while (z<1 || (z>4 && z != 2357));
        switch (z)
        {
        case 1:
            dead = klik(board, revealed, kondisi);
            jk++;
            break;

        case 2:
            flag(kondisi, revealed);
            jk++;
            break;

        case 3:
            rflag(kondisi, revealed);
            jk++;
            break;

        case 4:
            system("cls");
            dead = 4;
            break;

        case 2357: //Cheat untuk melihat seluruh isi bom di minesweeper bila user memasukkan angka 2357
            Tampilang(board);
            break;
        }
        if (z != 4)
            Tampilkar(kondisi);
    }


    jbuka = jumlhbuka(revealed, kondisi);
    if (dead == 1)
    {
        printf("\nANDA MENGENAI BOMB!!! \n\n");
    }
    else if (dead == 2)
    {
        printf("\nANDA MENANG!!! :)\n\n");

    }

    system("cls");

}


int main()
{
    int a, x;
    a = 1;

    while (a == 1)
    {
        printf("========================================\n");
        printf("  #     # # #   # ##### ##### SWEEPER\n");
        printf("  ##   ## # ##  # #     #     SWEEPER\n");
        printf("  # # # # # # # # ##### ##### SWEEPER\n");
        printf("  #  #  # # #  ## #         # SWEEPER\n");
        printf("  #     # # #   # ##### ##### SWEEPER\n");
        printf("========================================\n\n");
        x = menu();
        switch (x){
        case 1:
            system("cls");
            start();
            break;

        case 2:
            system("cls");
            a = 0;
            printf("\nThanks for Playing Our Game!!!\n\n");
        }
    }
}

我得到这个错误 错误C3861:'jumlhbuka':找不到标识符 我尝试谷歌搜索如何修复C3861 snd尝试解决方案仍然失败:( 请帮助我修复它,希望有人可以修复它 谢谢大家:)

1 个答案:

答案 0 :(得分:0)

只需将函数的原型行添加到文件顶部:

int jumlhbuka(int revealed[15][15], char kondisi[15][15]);

这样,它可以在实际实现之前找到jumlhbuka()。总之,它看起来像这样:

#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <conio.h>
#include <time.h>

// added line. Should do the trick
int jumlhbuka(int revealed[15][15], char kondisi[15][15]);

int menu()//menampilkan menu
{
// ...

或者,您也可以切换jumlhbuka()klik()的顺序。