C++ 使用函数、开关语句和多维数组的程序显示多个不合逻辑的错误

C++ 使用函数、开关语句和多维数组的程序显示多个不合逻辑的错误,c++,syntax-error,C++,Syntax Error,我的代码有问题,这真的毫无意义。某些事情在某一点上被称为错误,而不是在其他点上。它需要一个括号,但我看不出哪里需要它。IDE告诉我,在定义之前的函数声明之后需要分号,但只有在原型之后才需要分号。代码看起来很可靠,但这些错误不断出现。这是我的节目: #include <iostream> #include <iomanip> using namespace std; using std::istream; int FizzBuzz(int, int); int mai

我的代码有问题,这真的毫无意义。某些事情在某一点上被称为错误,而不是在其他点上。它需要一个括号,但我看不出哪里需要它。IDE告诉我,在定义之前的函数声明之后需要分号,但只有在原型之后才需要分号。代码看起来很可靠,但这些错误不断出现。这是我的节目:

#include <iostream>
#include <iomanip>

using namespace std;
using std::istream;

int FizzBuzz(int, int);

int main()
{
    int rowNum{};                      // Declaration and initialization of     variable number
    int columnNum{};                   // Declaration and initialization of  variable number
    int counter{};                     // Declaration/initialization of counter
    int array[4][4]{ { 60, 84, 50, 57 } ,{ 80, 75, 10, 54 } ,{ 81, 33, 55, 90 } ,{ 21, 35, 63, 45 } }; 
// Array initialization/Declaration
    char indicator{ 'n' };             // Continue or not?

    cout << "Welcome to my Fizzbuzz game, you are to guess the location of a "
         << "number which if is divisible by 5 and 3 you will win with "
         << "the output of Fizzbuzz. " << endl;

    for (;;)
    {
        counter++;

        switch (!(int FizzBuzz(int, int) % 15)) {
            case 1: printf("You win you got FizzBuzz!!! \n"); 
                cout << "It took you " << counter << " tries." << endl;
                break;

            case 0:

                switch (!(int FizzBuzz(int, int) % 3)) {
                    case 1: printf("Fizz, please try again. \n"); 
                        break;

                    case 0: 

                        switch (!(int FizzBuzz(int, int) % 5)) {
                            case 1:  printf("Buzz, please try again. \n"); 
                                break;

                            case 0: printf("please enter another input. \n"); 
                                break;
            }; break;
            }; break;
        }
        cout << endl << "Do you want to enter another array (please enter y     or n? ";
        cin >> indicator;           // Read indicator
        if (('n' == indicator) || ('N' == indicator))
            break;                  // Exit from loop
}

    int FizzBuzz(int, int)
    {
        int result{};

        cout << "Please enter an integer value between 0 and 3 "
             << "representing the row location of the number for the game, "
             << "then press the Enter key: " << endl;

        switch (rowNum)
        {
        case 0: cout << endl
            << "Now please enter a value for the location within the column." << endl;
            cin >> columnNum;

            result = array[rowNum][columnNum]
            break;

        case 1: cout << endl 
            << "Now please enter a value for the location within the column." << endl;
            cin >> columnNum;

            result = array[rowNum][columnNum]
            break;

        case 2: cout << endl 
            << "Now please enter a value for the location within the column." << endl;
            cin >> columnNum;

            result = array[rowNum][columnNum]
            break;

        case 3: cout << endl 
            << "Now please enter a value for the location within the column." << endl;

            result = array[rowNum][columnNum]
            break;

        default: cout << endl << "You entered an incorrect value."
            << endl;

            result = 0;
            break;
        }
        return result;
#包括
#包括
使用名称空间std;
使用std::istream;
int FizzBuzz(int,int);
int main()
{
int rowNum{};//变量number的声明和初始化
int columnNum{};//变量number的声明和初始化
int计数器{};//计数器的声明/初始化
int数组[4][4]{60,84,50,57},{80,75,10,54},{81,33,55,90},{21,35,63,45};
//数组初始化/声明
字符指示符{'n'};//是否继续?

cout您的代码中有许多错误。我建议打开编译器警告并分析警告和错误消息

main
中的多个位置,您有一些
intLiteral

int FizzBuzz(int, int) % intLiteral
这不是调用函数的方式。您可能应该使用

FizzBuzz(rowNum, columnNum) % intLiteral
相反。还要注意,您正在打开布尔值(例如
!(FizzBuzz(42,42)%3)
),并将其与整数
0
1
(例如
案例0:
)进行比较。为什么不改用
if
语句呢

main
的定义在声明
FizzBuzz
之前缺少一个结束
}

FizzBuzz
的定义也缺少一个结束语
}
,也缺少其参数的名称。这个定义应该从

int FizzBuzz(int rowNum, int columnNum)
{
变量
array
也可能是
FizzBuzz
的一部分,而不是
main


FizzBuzz
中的
result=array[rowNum][columnNum]
行末尾缺少分号。

从顶部开始。将光标放在大括号上/后面,并检查相应的闭合大括号是否高亮显示。或者使用#ifdef/#endif子句停用代码块,直到编译完成,然后开始重新添加部分代码,解决编译器错误,然后重复。相应的大括号将高亮显示。我不确定您使用#ifdef/#endif子句是什么意思。我已将表达式更新为switch(!(FizzBuzz(array,rowNum)%5)),但它将数组显示为错误。我修复了支架,但仍然显示错误的支架。它还显示两个开关中的错误。必须有开关语句。@phoenixCoder编辑了我的答案