Q:

how do i search a struct of arrays for a particular character without using pointers

i created a struct which has as one of its fields, a 2d array to store seats booked..in the main section, i have created an array of structs so as to store all the information.when i enter a row and column number, the program have to check if that seat has been booked already..the problem i have is that my program is not checking properly for this case..i have tried checking the entire array but i do not know how to properly do that..please assist me as i am still a newbie..
I have tried checking the entire array as you will see in my code..i have commented that part out, because i also tried only checking by only one instance of the array of structures
#include <iostream>
#include <string>
#include <conio.h>

using namespace std;

struct Simulate
{

        string seats[3][3] = {};
        string name = "";
        int age = 0;
        int rowNum, colNum;

};

``````````````````````````````````````````
void getinput(Simulate &book)
{

        cout<<"Enter your name: "<<endl;
        cin>>book.name;
        cout<<"Enter your age: "<<endl;
        cin>>book.age;
        cout<<"enter row number: "<<endl;
        cin>>book.rowNum;
        cout<<"enter column number: "<<endl;
        cin>>book.colNum;

}

void setSeats(Simulate &book)
{

    for (int i = 0; i < 3; i++)
    {

        for (int j = 0; j < 3; j++)
        {
            book.seats[i][j] = "o";

        }

    }
}

void bookMap(Simulate &book)

    {
        for (int i = 0; i < 3; i++)
        {
          //cout<<i<<endl;
          cout<<endl<<"\t";
          for (int j = 0; j < 3; j++)
          {

            cout<<book.seats[i][j]<<"  ";

          }
          cout<<endl;

        }

    }

void bookMapUpdated(Simulate &book)

    {
        for (int i = 0; i < 3; i++)
        {

          cout<<endl<<"\t";
          for (int j = 0; j < 3; j++)
          {

            cout<<book.seats[i][j]<<"  ";

          }
          cout<<endl;

        }

    }

/*
bool checkBooking(Simulate book[])

    {
                //assuming only 2 structs created
           for (int i = 0; i < 2; i++) {
           {

             if (book[i].seats[book[i].rowNum][book[i].colNum] == "o")
             {
                return true;
             }
             else
             {
                return false;
             }
    }
     */

bool checkBooking(Simulate book)

    {

             if (book.seats[book.rowNum][book.colNum] == "o")
             {
                return true;
             }
             else
             {
                return false;
            }
    }

```````````````````````````````````````````````` 
int main()

    {
      Simulate bookings[2];
      int i = 0;
      char answer;

      getinput(bookings[i]);
      setSeats(bookings[i]);
      bookMap(bookings[i]);

       if (checkBooking(bookings[i]) == true )
       {
         bookings[i].seats[bookings[i].rowNum][bookings[i].colNum] = "x";
       }
       else
       {
           cout<<"seat  booked please choose another seat"<<endl;
           cin>>bookings[i].rowNum>>bookings[i].colNum;
       }

       cout<<"do you want to make another booking y/n"<<endl;
       cin>>answer;

       while (answer == 'y' || answer =='Y')
       {
           i++;
           getinput(bookings[i]);
           bookMapUpdated(bookings[i]);

           if (checkBooking(bookings[i]) == true )
           {
             bookings[i].seats[bookings[i].rowNum][bookings[i].colNum] = "x";
           }
           else
           {
           cout<<"seat  booked please choose another seat"<<endl;
           cin>>bookings[i].rowNum;
           cin>>bookings[i].colNum;
           }

        cout<<"do you want to make another booking y/n"<<endl;
        cin>>answer;

       }

       system("pause");
        getch();
        return 0;
    }

A:

You are correctly looking for a character in a 2D array and using pointers would not help.
The problem is that you are using a different seats structure for every booking. To solve your problem, make the seats array unique and work with this one on every booking.
Apart from that, there is some problems with your code. First, you are using an array of two bookings, but you allow the user to input as many bookings as he wants. This will create memory corruption after 2 bookings. Second, when the seat is taken, you ask for another seat but you do not check if the new one is taken.

