这个函数中的某些东西使我的程序崩溃了!

发布于 2024-10-21 21:34:26 字数 4902 浏览 5 评论 0原文

你好,当我的程序开始执行 switch 语句的 case N 代码时,它崩溃了。我不知道为什么。有人愿意看一下吗?

代码:(我怀疑问题发生在 switch 语句的 case N 的某个地方)

#include "header.h"

void findSeats(int& FC_Row, int& FC_Col, int& EconRow, int& EconCol, int& ticketNum, int& rowNum, char& ticketType, char& seatType, int airplane[][6])
{
    int aisle,  col;
    char letterCol;

    if (ticketType = 'F')
        {
            switch (seatType)
            {
                case 'W':
                if (airplane[rowNum - 1][0] == 0)
                    {
                    airplane[rowNum - 1][0] = 1;
                    cout << "Your seat is " << (rowNum) <<  "A" << endl;
                    }
                else if (airplane[rowNum-1][FC_Col - 1] == 0)
                    {
                    airplane[rowNum - 1][FC_Col] = 1;
                    cout << "Your seat is " << (rowNum) <<  "D" << endl;
                    }
                else
                    {
                    cout << "There are no window seats in that row. Please choose a different row." << '\n' << "(use the seating chart to determin where open seats are.)" << '\n' << "Row Number:" <<  endl;
                    cin >> rowNum;
                    while (rowNum > (FC_Row))
                    {
                        cout << "That row is not located in our first class section. choose a row numbered 1-" << (FC_Row) << endl;
                        cin >> rowNum;
                    }
                    findSeats(FC_Row, FC_Col, EconRow, EconCol, ticketNum, rowNum, ticketType, seatType, airplane);
                    }
                    break;

                case 'A':
                aisle = (FC_Col / 2);
                if (airplane[rowNum - 1][aisle - 1] == 0)
                    {
                    airplane[rowNum - 1][aisle - 1] = 1;
                    cout << "Your seat is " << (rowNum) <<  "B" << endl;
                    }
                else if (airplane[rowNum-1][aisle] == 0)
                    {
                    airplane[rowNum - 1][aisle] = 1;
                    cout << "Your seat is " << (rowNum) <<  "C" << endl;
                    }
                else
                    {
                    cout << "There are no aisle seats in that row. Please choose a different row." << '\n' << "(use the seating chart to determin where open seats are.)" << '\n' << "Row Number:" <<  endl;
                    cin >> rowNum;
                    while (rowNum > (FC_Row))
                    {
                        cout << "That row is not located in our first class section. choose a row numbered 1-" << (FC_Row) << endl;
                        cin >> rowNum;
                    }
                    findSeats(FC_Row, FC_Col, EconRow, EconCol, ticketNum, rowNum, ticketType, seatType, airplane);
                    }
                    break;

                case 'N':
                col = 0;
                while (airplane[rowNum - 1][col] == 1)
                    {
                    for (col; airplane[rowNum - 1][col]; col++)
                        {
                        if (col > 3)
                            {
                                cout << "There are no available seats in that row. Please choose a different row." << '\n' << "(use the seating chart to determin where open seats are.)" << '\n' << "Row Number:" <<  endl;
                                cin >> rowNum;
                            }
                            while (rowNum > (FC_Row))
                            {
                                cout << "That row is not located in our first class section. choose a row numbered 1-" << (FC_Row) << endl;
                                cin >> rowNum;
                            }
                            ticketType, seatType, airplane);
                        }
                    }
                    airplane[rowNum - 1][col] = 1;
                    switch (col)
                    {
                        case 0:
                        letterCol = 'A';
                        break;
                        case 1:
                        letterCol = 'B';
                        break;
                        case 2:
                        letterCol = 'C';
                        break;
                        case 3:
                        letterCol = 'D';
                        break;
                    }
                    cout << "Your seat is " << (rowNum) <<  "letterCol" << endl;


            }
        }
}

删除对自身的函数调用解决了问题。

Howdy, When my program begins executing the code in case N of the switch statement it crashes. I am not sure why. Anyone care to take a gander?

Code: (I suspect the problem is occurring somewhere in case N of the switch statement)

#include "header.h"

void findSeats(int& FC_Row, int& FC_Col, int& EconRow, int& EconCol, int& ticketNum, int& rowNum, char& ticketType, char& seatType, int airplane[][6])
{
    int aisle,  col;
    char letterCol;

    if (ticketType = 'F')
        {
            switch (seatType)
            {
                case 'W':
                if (airplane[rowNum - 1][0] == 0)
                    {
                    airplane[rowNum - 1][0] = 1;
                    cout << "Your seat is " << (rowNum) <<  "A" << endl;
                    }
                else if (airplane[rowNum-1][FC_Col - 1] == 0)
                    {
                    airplane[rowNum - 1][FC_Col] = 1;
                    cout << "Your seat is " << (rowNum) <<  "D" << endl;
                    }
                else
                    {
                    cout << "There are no window seats in that row. Please choose a different row." << '\n' << "(use the seating chart to determin where open seats are.)" << '\n' << "Row Number:" <<  endl;
                    cin >> rowNum;
                    while (rowNum > (FC_Row))
                    {
                        cout << "That row is not located in our first class section. choose a row numbered 1-" << (FC_Row) << endl;
                        cin >> rowNum;
                    }
                    findSeats(FC_Row, FC_Col, EconRow, EconCol, ticketNum, rowNum, ticketType, seatType, airplane);
                    }
                    break;

                case 'A':
                aisle = (FC_Col / 2);
                if (airplane[rowNum - 1][aisle - 1] == 0)
                    {
                    airplane[rowNum - 1][aisle - 1] = 1;
                    cout << "Your seat is " << (rowNum) <<  "B" << endl;
                    }
                else if (airplane[rowNum-1][aisle] == 0)
                    {
                    airplane[rowNum - 1][aisle] = 1;
                    cout << "Your seat is " << (rowNum) <<  "C" << endl;
                    }
                else
                    {
                    cout << "There are no aisle seats in that row. Please choose a different row." << '\n' << "(use the seating chart to determin where open seats are.)" << '\n' << "Row Number:" <<  endl;
                    cin >> rowNum;
                    while (rowNum > (FC_Row))
                    {
                        cout << "That row is not located in our first class section. choose a row numbered 1-" << (FC_Row) << endl;
                        cin >> rowNum;
                    }
                    findSeats(FC_Row, FC_Col, EconRow, EconCol, ticketNum, rowNum, ticketType, seatType, airplane);
                    }
                    break;

                case 'N':
                col = 0;
                while (airplane[rowNum - 1][col] == 1)
                    {
                    for (col; airplane[rowNum - 1][col]; col++)
                        {
                        if (col > 3)
                            {
                                cout << "There are no available seats in that row. Please choose a different row." << '\n' << "(use the seating chart to determin where open seats are.)" << '\n' << "Row Number:" <<  endl;
                                cin >> rowNum;
                            }
                            while (rowNum > (FC_Row))
                            {
                                cout << "That row is not located in our first class section. choose a row numbered 1-" << (FC_Row) << endl;
                                cin >> rowNum;
                            }
                            ticketType, seatType, airplane);
                        }
                    }
                    airplane[rowNum - 1][col] = 1;
                    switch (col)
                    {
                        case 0:
                        letterCol = 'A';
                        break;
                        case 1:
                        letterCol = 'B';
                        break;
                        case 2:
                        letterCol = 'C';
                        break;
                        case 3:
                        letterCol = 'D';
                        break;
                    }
                    cout << "Your seat is " << (rowNum) <<  "letterCol" << endl;


            }
        }
}

removing the function call to itself solved the issue.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

柏林苍穹下 2024-10-28 21:34:26

我怀疑 rownum0

负索引不好。

I suspect rownum is 0

Negative indexes are bad.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文