你好,当我的程序开始执行switch语句的情况N中的代码时,它崩溃了。我不知道为什么。有人想要带一个雄鹅?
代码:(我怀疑问题是在switch语句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;
}
}
}
删除对自身的函数调用解决了这个问题。
答案 0 :(得分:2)
我怀疑rownum
是0
负面指数不好。