这个函数中的某些东西使我的程序崩溃了!
你好,当我的程序开始执行 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我怀疑
rownum
是0
负索引不好。
I suspect
rownum
is0
Negative indexes are bad.