0

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.

31st Oct 2016, 2:18 PM
Ryn
Ryn - avatar
2 Respuestas
+ 4
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 :)
31st Oct 2016, 10:06 PM
Zeke Williams
Zeke Williams - avatar
+ 1
import numpy as np data = np.array([1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0]) row = int(input()) arr= np. reshape(data,(6, 5)) print(arr[row])
9th Oct 2021, 2:01 PM
Biswajit Biswal
Biswajit Biswal - avatar