Need Help With Program

dxf
Last edited on
I made some updates but the * still wont appear in my array, and I cant figure it out.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <iostream>
#include <iomanip>
#include <cstdlib>

using namespace std;

const int NOR = 13; //number of rows
const int NOC = 7; //number of columns
enum seatColumn {Row,A,B,C,D,E,F};

void displaySeats(string array[][NOC],char column, int row );
void bookSeat(char &ticketType, char &column, int &row);

int main(int argc, char** argv) {
	
	char response, 
		 ticketType,
	   	 column;
		 
	int row;
	
	string array[NOR][NOC];
	          
    cout<<"Do you wish to book a seat? (Y/N)"<<endl;
    cin>>response;
    
    while (response == 'Y' || response == 'y')    
    { 
    	displaySeats(array, column, row);
		bookSeat(ticketType, column, row);	
	 	
   cout<<"Do you wish to book another seat? (Y/N)"<<endl;      
    cin>>response;  
    if (response == 'N' || response == 'n')
    return 0;
	}	

system("PAUSE");
return EXIT_SUCCESS;
}            
     
//--------------------function----------------------------	

void bookSeat(char &ticketType, char &column, int &row){

	cout<<"Enter your ticket type. (First Class = F, Business Class = B, Economy Class = E)";
	cin>>ticketType;
	{
	if (ticketType == 'F' || ticketType == 'f')
		cout<<"Which row would you like to sit in? (1 2)\n";
		
	if (ticketType == 'B' || ticketType == 'b')
		cout<<"Which row would you like to sit in? (3 4 5 6 7)\n";
		
	if (ticketType == 'E' || ticketType == 'e')
		cout<<"Which row would you like to sit in? (8 9 10 11 12 13)\n";
	}
	
	cin>>row;
	
	cout<<"Which seat would you like to sit in (A B C D E F)?\n";
	cin>>column;
}
	

void displaySeats(string array[][NOC], char column, int row){
	
	cout<<"The following seats are currently available\n";
	cout<<"X = Reserved\n";
	cout<<"* = Available\n";
	
	cout<<left<<setw(7)<<"Row"<<setw(6)<<"A"<<setw(6)<<"B"<<
	setw(6)<<"C"<<setw(6)<<"D"<<setw(6)<<"E"<<setw(6)<<"F\n";
 
	{for(int r=0; r<NOR; ++r)
	 for(int c=0; c<NOC; ++c)
		array[NOR][NOC]="*";
	}
 
 
	 {for(int r=0; r<NOR; ++r)
     {cout<<r+1<<endl;
           
           for(int c=0; c<NOC; ++c)
           {cout<<array[r][c];
        }
	
		
}}}
Line 77 is incorrect:
 
    array[NOR][NOC]="*";

On my system it caused the program to end with an exception. (access violation)

array[NOR][NOC] is outside the array bounds.

It should be
 
    array[r][c] = "*";
Thanks! I finally got the array to display correctly, also I made some more changes to the code. But I have no clue how to change the * to an X once the user books a seat. Any ideas?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include <iostream>
#include <iomanip>
#include <cstdlib>

using namespace std;

const int NOR = 13; //number of rows
const int NOC = 6; //number of columns

void displaySeats(string array[][NOC],char column, int row );//shows user seating chart
void bookSeat(char &ticketType, char &column, int &row);//allows user to book seat

int main(int argc, char** argv) {
	
	char response, 
		 ticketType,
	   	 column;
		 
	int row;
	
	string array[NOR][NOC];
	
	cout<<"Do you wish to book a seat? (Y/N)"<<endl;
    cin>>response;
    cout<<endl;
    
    {string array[NOR][NOC]= 
				   {{"*","*","*","*","*","*"},
					{"*","*","*","*","*","*"},
					{"*","*","*","*","*","*"},
					{"*","*","*","*","*","*"},
					{"*","*","*","*","*","*"},
					{"*","*","*","*","*","*"},
					{"*","*","*","*","*","*"},
					{"*","*","*","*","*","*"},
					{"*","*","*","*","*","*"},
					{"*","*","*","*","*","*"},
					{"*","*","*","*","*","*"},
					{"*","*","*","*","*","*"},
					{"*","*","*","*","*","*"}};
	}
    
	while (response == 'Y' || response == 'y')    
    { 	
    	displaySeats(array, column, row);
		bookSeat(ticketType, column, row);	
	 	
    cout<<"Do you wish to book another seat? (Y/N)"<<endl;      
    cin>>response;  
    if (response == 'N' || response == 'n')
    return 0;
	}

system("PAUSE");
return EXIT_SUCCESS;
}            
     
//--------------------function----------------------------	

void bookSeat(char &ticketType, char &column, int &row){

	cout<<"Enter your ticket type.\nFirst Class = F\nBusiness Class = B\nEconomy Class = E"<<endl;
	cin>>ticketType;
	{
	if (ticketType == 'F' || ticketType == 'f')
		cout<<"Which row would you like to sit in? (1 2)\n";
		
	if (ticketType == 'B' || ticketType == 'b')
		cout<<"Which row would you like to sit in? (3 4 5 6 7)\n";
		
	if (ticketType == 'E' || ticketType == 'e')
		cout<<"Which row would you like to sit in? (8 9 10 11 12 13)\n";
	}
	
	cin>>row;
	
	cout<<"Which seat would you like to sit in (A B C D E F)?\n";
	cin>>column;
}
	
//--------------------function----------------------------	

void displaySeats(string array[][NOC], char column, int row){
	


	{cout<<"The following seats are currently available\n";
	 cout<<"X = Reserved\n";
	 cout<<"* = Available\n";
	 cout<<endl;
	 	
	 cout<<left<<setw(7)<<"Row"<<setw(6)<<"A"<<setw(6)<<"B"<<
	 setw(6)<<"C"<<setw(6)<<"D"<<setw(6)<<"E"<<setw(6)<<"F"<<endl;
	 cout<<"_______________________________________"<<endl<<endl;
 	}
 	
 	for(int r=0; r<NOR; ++r)
    {cout<<left<<setw(2)<<r+1 ;
	 	for(int c=0; c<6; ++c)
       {cout<<right<<setw(6)<<array[NOR][NOC];
       }
       cout << endl;
    }
	cout<<endl;	
}
Topic archived. No new replies allowed.