I'm supposed to write a program that displays a theater seating, ask the user to give each row a price, then ask if they want to purchase a ticket. their response has to be saved into a 2d array and change the EMPTY seat to a TAKEN seat. The last past is where I'm having trouble. Any suggestions? I'm new to c++ so I'm having a really hard time figuring things out. any little advice will help.
for(int i = 0; i < row; i++)
{
for(int j=0;j<col;j++)
{
map[row2][col2]=TAKEN;
}
}
Why are you updating the same spot map[row2][col2] inside this loop? You should only do it once.
Try changing the code above to:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
// Check if seat is free
if(map[row2][col2] == TAKEN)
{
cout << "This seat is taken! Try another one. \n";
continue; // start the loop again
}
else // and if it is - sell the ticket
map[row2][col2]=TAKEN;
// Add the next loop to immediately see the effects:
for (int i = 0; i < row; i++){
for(int j = 0; j < col; j++){
cout << map[i][j];
}
cout << endl;
}