Code:
#include <iostream>
using namespace std;
void initalize(char passengers[][6][4][40]);
void menu(char passengers[][6][4][40]);
void enterpass(char passengers[][6][4][40]);
void dispsingle(char passengers[][6][4][40]);
void dispall(char passengers[][6][4][40]);
void initalize(char passengers[][6][4][40])
{
int a,R;
for(a=0;a<10;a++)
{
for(R=0;R<6;R++)
{
passengers[a][R][0][0] = '\0';
}
}
}
void menu(char passengers[][6][4][40])
{
int choice=0;
while (choice == 0)
{
cout << "Menu" << endl << "1) Enter passenger" << endl << "2) Display single passenger info" << endl << "3) Display all passengers" << endl << "4) Exit program" << endl;
cout << "Selection: ";
cin >> choice;
switch (choice)
{
case 1:
{
enterpass(passengers);
choice = 0;
break;
}
case 2:
{
dispsingle(passengers);
choice = 0;
break;
}
case 3:
{
dispall(passengers);
choice = 0;
break;
}
case 4:
{
cout << "Thank you for using LaR 5!" << endl;
break;
}
}
}
}
void enterpass(char passengers[][6][4][40])
{
int row=0, column=0;
while (row != -1 && column != -1)
{
cout << endl << "Which passenger? (Format: row column) Use 0 0 to stop ";
cin >> row;
cin >> column;
cin.get();
row -= 1;
column -=1;
if (row > 9 || row < -1)
{
cout << "Invalid row" << endl;
}
else if (column > 5 || column < -1)
{
cout << "Invalid column" << endl;
}
else if (row > -1)
{
cout << endl << "First name: ";
cin.getline(passengers[row][column][0], 40);
cout << "Last name: ";
cin.getline(passengers[row][column][1], 40);
cout << "Social Security NumRer: ";
cin.getline(passengers[row][column][2], 40);
cout << "Destination city: ";
cin.getline(passengers[row][column][3], 40);
}
}
}
void dispsingle(char passengers[][6][4][40])
{
int row=-1, column=-1;
cout << endl << "Enter row and column: ";
cin >> row >> column;
row -=1;
column -= 1;
if (row < 0 || column < 0 || row > 9 || column > 5)
{
cout << "Invalid Passenger!";
return;
}
else
{
cout << endl << "Displaying information for row " << row+1 << ", column " << column+1 << ":" << endl;
cout << "First name:\t\t\t" << passengers[row][column][0] << endl;
cout << "Last name:\t\t\t" << passengers[row][column][1] << endl;
cout << "Social Security NumRer:\t\t" << passengers[row][column][2] << endl;
cout << "Destination:\t\t\t" << passengers[row][column][3] << "\n\n";
}
}
void dispall(char passengers[][6][4][40])
{
int a, R;
for (a=0;a<10;a++)
{
if (passengers[a][0][0] != '\0' || passengers[a][1][0] != '\0' || passengers[a][2][0] != '\0' || passengers[a][3][0] != '\0' || passengers[a][4][0] != '\0' || passengers[a][5][0] != '\0')
{
cout << "Row " << a+1 << ":\t";
}
for (R=0;R<6;R++)
{
if (passengers[a][R][0] != '\0')
{
cout << passengers[a][R][0] << " " << passengers[a][R][1] << " ";
}
if (R == 5)
{
cout << endl;
}
}
}
}
int main()
{
char passengers[10][6][4][40];
initalize(passengers);
menu(passengers);
return 0;
}
Everything works and is char oriented now. The 'b' variables in the code are causing the bold problem, lol, changed all b's to R's. You should worship char arrays. They are the best thing in the language.