Question ..

I have made a program that prompts the user for their name, which movie they will be watching, and the seat letter and number.. i wanna ask what code/process should i use when it comes to the reservation of seats. im having a hard time now. Would appreciate help.

My current code.
#include <iostream>
#include <string>
#include <stdlib.h>
#include <iomanip>

using namespace std;
int main ()
{
int choice,movie,seatNumber;
string name;
char seatLetter;
do
{
system("cls");
cout<<"*****WELCOME*****\n"
<<"1. Cineme One \n"
<<"2. Cineme Two \n"
<<"3. Exit\n"
<<"Please Choose one: ";
cin>>choice;
}while (choice!=1&&choice!=2&&choice!=3);

switch (choice)
{
case 1:
system("cls");
cin.ignore();
cout<<"Welcome to Cinema One!"<<endl;
cout<<"Enter your name: "<<endl;
getline(cin,name);
{
system("cls");
cout<<"****MOVIES*****\n"
<<"1. Avengers\n"
<<"2. The amazing Spiderman\n"
<<"Enter the Number: ";
cin>>movie;



switch (movie)
{
case 1:
{

system("cls");
cout<<" AVENGERS "<<endl;
cout<<"----------------------------------SCREEN-----------------------------\n"
<< "A| 1 2 3 4 5 6 7 8 9 10 A| 11 12 13 14 15 16 17 18 19 20\n"
<< "B| 1 2 3 4 5 6 7 8 9 10 B| 11 12 13 14 15 16 17 18 19 20\n"
<< "C| 1 2 3 4 5 6 7 8 9 10 C| 11 12 13 14 15 16 17 18 19 20\n"
<< "D| 1 2 3 4 5 6 7 8 9 10 D| 11 12 13 14 15 16 17 18 19 20\n"
<< "E| 1 2 3 4 5 6 7 8 9 10 E| 11 12 13 14 15 16 17 18 19 20\n"
<< "F| 1 2 3 4 5 6 7 8 9 10 F| 11 12 13 14 15 16 17 18 19 20\n"
<< "G| 1 2 3 4 5 6 7 8 9 10 G| 11 12 13 14 15 16 17 18 19 20\n"
<< "H| 1 2 3 4 5 6 7 8 9 10 H| 11 12 13 14 15 16 17 18 19 20\n"
<< "I| 1 2 3 4 5 6 7 8 9 10 I| 11 12 13 14 15 16 17 18 19 20\n"
<< "J| 1 2 3 4 5 6 7 8 9 10 J| 11 12 13 14 15 16 17 18 19 20\n";


do
{
cout<<"Enter Seat(Letter then Number): ";
cin>>seatLetter>>seatNumber;
seatLetter=toupper(seatLetter);

}

while (seatLetter!='A'||seatLetter!='B'||seatLetter!='C'||seatLetter!='D'||seatLetter!='E'||seatLetter!='F'||seatLetter!='G'||seatLetter!='H'||seatLetter!='I'||seatLetter!='J');

/*do
{
cout<<"Enter Seat Number: ";
cin>>seatNumber;
if (seatNumber!=1 && seatNumber!=2&& seatNumber!=3&& seatNumber!=4&& seatNumber!=5&& seatNumber!=6&& seatNumber!=7&& seatNumber!=8&& seatNumber!=9&& seatNumber!=10&& seatNumber!=11&& seatNumber!=12&& seatNumber!=13&& seatNumber!=14&& seatNumber!=15&& seatNumber!=16&& seatNumber!=17&& seatNumber!=18&& seatNumber!=19&& seatNumber!=20);

}while (seatNumber!=1 && seatNumber!=2&& seatNumber!=3&& seatNumber!=4&& seatNumber!=5&& seatNumber!=6&& seatNumber!=7&& seatNumber!=8&& seatNumber!=9&& seatNumber!=10&& seatNumber!=11&& seatNumber!=12&& seatNumber!=13&& seatNumber!=14&& seatNumber!=15&& seatNumber!=16&& seatNumber!=17&& seatNumber!=18&& seatNumber!=19&& seatNumber!=20);
*/

}//end switch case 1
break;
}//end switch
}//end case display



break;//end case 1
}
}//end main
closed account (Dy7SLyTq)
for the reservation of seats i would use multidimensional arrays (well vectors actually but you can learn that later)
multi dimensional arrays huhh. alright im going to try to do that. will have a long way to go though since we havent discussed about this in class. any suggestions on multidimensional arrays/vectors?
closed account (N36fSL3A)
I wouldn't use multidimensional arrays, but they're straightforward.

Let's say you want to make a game board. You could possibly use multidimensional arrays to represent it. This is how a multidimensional array looks:
int board[5][5];

All it is is an array of arrays.

You can theoretically make an array of any dimension, the one shown above was a 2D array.

As you move up you dimensions, you consume more and more memory. So be careful.

This is how you'd set the game board.
1
2
3
4
5
6
int board[5][5] =
{{1, 0, 1, 0, 1},
 {0, 1, 0, 1, 0},
 {1, 0, 1, 0, 1},
 {0, 1, 0, 1, 0},
 {1, 0, 1, 0, 1}};


Let's move away from games, and just make a standard array.

int arr[10][20];

Let's say I want to make the variable in the 5th row and 10th column equal to 15.

We have two variables. Variables m and n.

1
2
int n = 0;
int m = 0
N will represent the row, m will represent the column.

Now, all we have to do to set a variable in on the 5th row and 10 columns is set the variables to where the array element is located.

1
2
m = 5;
n = 10


Now just put the variables in the appropriate places, and change the value to what you'd like.

arr[n][m] = 15;

And you're done.
Last edited on
closed account (Dy7SLyTq)
dont worry about vectors right now if you havent learned arrays yet. and while i dont see it too often in pure c++ code, built in arrays can be useful, just like goto. although i have never needed to use either

edit: in c++ at least. batch and python/php are a different matter
Last edited on
Thanks guysss.

i would also like to ask how would i code a scenario that when a user has already chosen that particular seat.. it would show a different variable. X for example for the taken ones. Other costumers wont be able to take that seat aswell..
Last edited on
Topic archived. No new replies allowed.