help!!!!my movie theatre program!!!

# include <iostream>
# include <iomanip>
using namespace std;

void seats( double [] , int);
void mapSeats();
void payManage();

int main()
{
const int rowNum = (20.0);
double rowValue[rowNum]; //array to hold row pices
char selection;
int row2, col2;
const char TAKEN = '#';//seats taken
const char EMPTY = '*';//seats free
const int row = 20;//number of rows
const int col = 15;//number of col
char map[row][col];//array to hold seat chart



for(int i= 0;i<row;i++)//initiating array
{
for (int j=0;j<col;j++)
{
map[i][j]=EMPTY;
}
}

mapSeats();

seats(rowValue, rowNum);//ask user to enter price of each row
cout << endl;

do
{
cout << "MOVIE THEATER MENU" << endl;
cout << "------------------" << endl;
cout << "1) Sell a ticket" << endl;
cout << "2) Total sell and exit" << endl;
cout << "Please make a selection: ";
cin >> selection;

if(selection =='1')
{
cout << "Please enter a row number and a seat number for the ticket: " ;
cout << "Row # :" ;
cin >> row2;
cout << endl;
cout << "Seat # :" ;
cin >> col2;
cout << endl;

// 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;
}


}
else if(selection =='2')
{
cout << "TOTAL TICKETS SOLD: " << endl;
cout << "TOTAL REVENUE: ";
}
else if(selection != '1' || selection !='q' || selection !='Q')
{
cout << "Invalid selection." << endl;
}
}while(selection != '1' || selection !='q' || selection !='Q');


system("PAUSE");
return 0;
}


void seats(double rowPrice[], int row)
{
int sum;
cout << "Please enter a ticket price for each row." << endl;

for(int i = 0 ; i < row; i++)
{
cout << "Row # " << i+1 << ": " ;
cin >> rowPrice[i];
}
}

void mapSeats()
{
const char TAKEN = '#';//seats taken
const char EMPTY = '*';//seats free
const int rw=20;
const int cl=15;

cout << "Seats " ;
for(int k = 0 ; k <15;k++) //loop to display nums 0 to 14
{
cout << fixed<< setw(2) << " " << k ;
}

for(int i=0;i<rw;i++)//making array display what's in it
{
cout << endl<< "Row " << i;
for(int j=0;j<cl;j++)
{
cout << fixed<< setw(2) << "" << EMPTY;
}
}
cout << endl;
}
Last edited on
Hello,

Could you please update your post and use the code tags (select the code you wrote and click the <> button), this will add line numbers so we can tell you where in your code we are talking about. Also the formatting would be preserved, making your code easier to read.

To finish your project you will first have to get your code to compile.
In this line you are trying to put a floating point value in an integer variable const
const int rowNum = (15.0);
, why not just put an integer value of 15? I can't imagine any half rows.

When you reach this line in your code:
double rowValue[rowNum], rowPrice[i];
the variable i does not yet exist. I expect it should be the variable col, but that one is declared 7 lines later so you can't use it yet.
Also I think "rowNum" in the previous line and "row" that is declared 6 lines further should probably be the same variable.

In
void seats(double rowPrice[], int row)
you again use two variables "cost" and "total" that don't exist in that scope.

If you solve these issues you will be able to display your matrix of empty seats.

As for your second question:
First make sure that what you have is working. Only after that, have a look at: http://www.cplusplus.com/doc/tutorial/files/
Last edited on
thank you so much! I'll start working on it right now!
In addition to what Nico mentioned:

Line 85: Your while condition is bogus. The condition will always be true. If selection is 2, then != 1 will be true. If selection is 1, then != 2 will be true. You want:
 
  while (! (selection == 1 || selection == 2))


Line 107: mapSeats() should display the seating array at any point in time. i.e. lines 64-71 should call mapSeats() to display the current status of the seating array.
Topic archived. No new replies allowed.