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 " << (rowNu开发者_开发技巧m) << "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.
I suspect rownum
is 0
Negative indexes are bad.
精彩评论