I am currently working on a project called movie reservation and I am almost done, the only problem right now is the seats. I have no idea how I can display 200 seats and identify whether a seat is already taken or not. Also, each row must be referred as character 'A' for the first and 'J' for the last and it should be with also a number. So for example the first row will have something like 'A1 or A5 or A3' while the last seats will be J1 J2 J3 and so on... Here is my code, I only need to know how to do the seats... please help me.

#include <iostream>

using namespace std;

int main()
{
     int movie; double price(2.35); double price2(2.41);int actors;
     int information; int wallstreet; int seatnumber(1-100);

     cout << "***********  Welcome to AT1 cinema  ************* \n"     
          << "Choose movie below, type the movie and the number you want: \n"  
          << "1. Wallstreet\n" 
          << "2. The Social Network\n"
          << "3. Takers\n";
     cout << endl;

     cin >> movie;

     if (movie == 1)
     cout << "Wallstreet" <<endl;
     else if (movie == 2)
     cout << "The Social Network" << endl;
     else if (movie == 3)
     cout << "   " << endl;


{
cout << "Choose your seat number: " <<endl;
cout << endl;
cin >> seatnumber;
cout << endl;
}

{
     cout << "Here is your official receipt: " <<endl;
}
{ 
   if (movie == 1)
     cout << "Wallstreet" <<endl;
     else if (movie == 2)
     cout << "The Social Network" << endl;
     else if (movie == 3)
     cout << "You selected the movie: Takers" << endl;
}
{
     cout << "You selected the seat number: " << seatnumber << endl;
}
{    if (movie == 1)
     cout << "$2.35" <<endl;
     else if (movie == 2)
     cout << "$2.45" << endl;
     else if (movie == 3)
     cout << "$2.55" << endl;
}





system ("pause");

return 0;

}

Edited 3 Years Ago by mike_2000_17: Fixed formatting

FrancisLazo
Deleted Member

Place code between the code tags, which are [ code] and [ /code] (without the space)

I would consider using a matrix to represent the seat data, and a structure holding the information for each seat.

matrix = 2 dimensional array

For the letter-index system, I would simply create an alphabet in the code, like so: const char *alphabet = "ABCDEFGHIJ"; The index of the letter in the array(alphabet) can be used as the index, and it will allow you to logically use seats like "A1" and "J2".

of course you may opt to do it totally different, you don't have to listen to every fool willing to type ;)


I'm also wondering why you opted to define a new scope for various portions of your main() function.

I'm also wondering why you opted to define a new scope for various portions of your main() function. << what is this suppose to mean?? what is new scope and various portions of main() function???

Thanks for the help sir, though I haven't fully learned arrays yet I'll try to study it. Any more tips you got there sir?

struct seat
{
    bool reserved;
    string passengerName;
    int movie; // 0, 1, or 2
    // possibly add a price and seat number here, but depending on
    // how you organize things, maybe not.
};

seat seats[10][20];

Something like that. reserved is false if the seat isn't taken.

To expand on the constant arrays idea, for quick movie lookup,

const string movie_names[3] = {"Wall Street", "The Social Network", "Taken"};
const double movie_prices[3] = {2.35, 2.45, 2.55};
{
cout << "Here is your official receipt: " <<endl;
}

Those curly braces (the '{' and '}') define a new local scope. It seems hard for me to define "scope" for you, I really can't think of a good definition for it. But google can... Beloved Google.

{ if (movie == 1)
cout << "$2.35" <<endl;
else if (movie == 2)
cout << "$2.45" << endl;
else if (movie == 3)
cout << "$2.55" << endl;
}

You can delete the red brackets and the program will be the same. I can't define "scope" either, but by adding the brackets, you've added another layer of scope unnecessarily. The compiler couldn't care less. It neither adds nor detracts from your program, but it adds a level of puzzlement to the reader, so you should delete them.

Well the way you have used them doesn't make much difference from what I saw, but it certainly could cause a problem if you didn't know it was a new scope.

Those curly braces (the '{' and '}') define a new local scope. It seems hard for me to define "scope" for you, I really can't think of a good definition for it. But google can... Beloved Google.

It's okay sir, I think I understand now. Thank you very much! :)

This article has been dead for over six months. Start a new discussion instead.