Reserving cinema seats in 2d array [4][9]

in need to change the value in the array from '-' to R when the seats are reserve..and 'Q' if the seats does not exist...there are some cout question like in which row you want to seat? how many seats.?.how to go aroud with this.?.the seats are already displayed..can't reserve them.


10/31/2016 2:18:28 PM


1 Answer

New Answer


say the user inputs row 4 and the 7th seat in on that row. After the array has been declared as you had it (char array [4][9] ), the 7th seat on row 4 would be array[3][6] = 'R' a good way to do this automatically is to use a nested for loop: int rowChoice, seatInRow; cout << "Enter the row you want, then space then seat in that row: "; cin >> rowChoice >> seatInRow; cout << endl; for (int i = 0; i < 4; i++) { for (int j = 0; j < 9; j++) { if (rowChoice == i && seatInRow == j) { array[ i ][ j ] = 'R'; } } } cout << "Your seat has been reserved. Thank you. " << endl; As for the number of seats they want to reserve, you could place all of this in a while loop, but just before the while loop, have them enter in how many seats they want: int nSeats, x(0); cout << "How many seats will you be reserving today: "; cin >> nSeats; while(x != nSeats) { //code above x++; } I hope this answers your questions :)