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

Multiple illogical errors showing for program utilizing a function, switch statement, and multidimensional array

我的代码有问题,但确实没有意义。某些事情在某一时刻被称为错误,而在其他时刻则没有。它需要一个括号,但我什至看不到需要它的地方。 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;

我真的不明白问题出在哪里,因为我什至在写这篇文章时得到了帮助。

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

main 的多个地方你有一些 intLiteral:

int FizzBuzz(int, int) % intLiteral

这不是调用函数的方式。你应该使用像

这样的东西
FizzBuzz(rowNum, columnNum) % intLiteral

相反。另请注意,您正在切换布尔值(例如 !(FizzBuzz(42, 42) % 3))并将其与整数 01(例如 case 0:)进行比较。为什么不使用 if 语句呢?

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

FizzBuzz 的定义也缺少结束符 },并且也缺少其参数的名称。该定义可能应该以

开头
int FizzBuzz(int rowNum, int columnNum)
{

变量 array 也应该是 FizzBuzz 而不是 main 的一部分。

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