C++ intro class

I need help passing the "seat array" into the buyticket function. I have made the seating chart but i cant get the '#' to change into '*' when purchased. The seat array should all have the value of the char '#' but it doesnt seem to pass into the buyticket like that. It will always display "sorry this ticket has already been sold" when i try to buy a ticket.




#include<iostream>
#include<iomanip>

using namespace std;
// seat chart row and cols total
int const ROW= 15;
int const COLS= 30;
// main menu var
char choice=' ';

// user values row and col
int row;
int col;
// grand total ticket for ALL the customers
double totaltix=0.0;
// total ticket for ONE customer
double totaltixcust=0.0;
int totalclients=0;

int i;
int const Num_Rows=15;
// array seating
char seat[ROW][COLS];
// ticket price
double price [Num_Rows];
int x;
// available seat - seat taken

const char avaliableseat= '#',takenseat= '*';

//void prototype
void getPrice(double []);
void showPrice(double [], int);
void tixPurchase();
void buyticket(char[ROW][COLS]);
void showChart(char [ROW][COLS]);
void main_Menu();




int main()
{
getPrice(price);

main_Menu();

return 0;
}

// ------------------------------------------------------

void getPrice(double price[])
{

// get prices for the 15 rows feeding the price array

const int Num_Rows=15;

for (int i = 0; i < Num_Rows; i++)
{
cout<< "Please enter the price for row "<<setw(2)<<i+1<<": ";
cout<<fixed<<showpoint<<setprecision(2);
cin >> price [i];

}

}
//----------------------------------------------------------------------------

void showPrice(double price[], int x)
{

// Display all the price array values added in getprice()

const int Num_Rows=15;

cout<<"\nTicket Prices By Row "<<endl<<endl;
cout<<" Row Price"<<endl;
cout<<" --- -----"<<endl;

for(int x=0; x < Num_Rows; x++)
{
cout << setw(10) << x+1 << setw(9) << price[x] << endl;

}
cout << "\n\n\nPress the Enter key to continue.";
cin.ignore();
cin.get();

}

//-----------------------------------------------------------

void showChart(char seat [ROW][COLS])
{
const int ROW = 15;
const int COLS = 30;
//char seat[ROW][COLS];
int x;
int y;

// for loop to go through the array

for(x = 0; x <= ROW; x++)
{
for(y = 0; y < COLS; y++)
{
seat[x][y] = avaliableseat;
}

}
cout << "\n\t\tSeats";
cout << "\n 123456789012345678901234567890" << endl;
cout<<endl;


for(x = 0; x < ROW; x++)
{

cout <<"Row"<<setw(3)<< x+1<<setw(3);
for(y=0; COLS > y; y++)
{
cout<< seat[x][y];

}
cout << endl;
}

cout << endl;

cout << "\n\n\n\tLegend:\t* = Sold";
cout << "\n\t\t# = Available";
cout << "\n\n\nPress the Enter key to continue.";
cin.ignore();
cin.get();


}


//--------------------------------------------------------------------


void tixPurchase()
{

// show the seat chart and call the function to buy the tickets

// var used to see or not the seat chart before buy the ticket
char choice=' ';

// var for the while
// char otherSeat='y';


cout << "\n\t\t C++ Theatre" << endl;
cout << "\t\tTicket Purchase Opportunity" << endl << endl;
cout << "Do you wish to view the chart of available seats \n"
<< "before making your selections (y/n)? ";
cin>>choice;

if(choice== 'y' || choice== 'Y')
{
// show the seat chart if the user want it calling the fuction showChart()

showChart(seat);
}

else (choice== 'n' || choice== 'N');
{
// call the function buyticket()

//IF YOU DIDNT CALL THE FUCTION SHOWCHART () THE IF/ELSE CONDITION IN BUYTICKET() IS NOT WORKING
//BECAUSE THE SEAT[][] ARRAY IS EMPTY .SO IT ALWAY EXECUTE THE ELSE . THEN THE SHOWCHART()
//NEED TO BE MODIFY FROM # TO * FOR AN SPECIF ROW AND COL INSIDE BUYTICKET()

buyticket(seat);
}

}


//**************************************

void buyticket (char seat [ROW][COLS])
{

// fuction to buy as many tickets as the user want

// var for the while
char otherSeat='y';

while (otherSeat== 'Y' || otherSeat== 'y')

{

cout << "\nPlease enter desired row number (1-" << ROW << "): ";
cin>>row;

// row must be <=15

while(row<1 || row>15)
{
cout << "Row must be between 1 and " << ROW << ". Please re-enter: ";
cin>>row;
}
cout << "\nPlease enter desired seat number (1-" << COLS << "): ";
cin>>col;

// cols must be <=30

while(col<1 || col>30)
{
cout << "Seat must be between 1 and " << COLS << ". Please re-enter: ";
cin>>col;
}


// check to see of seat is available ="#"
if(seat[row][col]== avaliableseat )
{
// if the seat is available
cout << "\nPurchase confirmed\n";

// mark the seat is taken

//UPDATE SHOWCHART FUNCTION IN ORDER TODISPLAY THE * SYMBOL IN THE CHART
seat[row][col]= takenseat;
}

else (seat[row][col]== takenseat);
{
// seat is taken . the user cant buy that ticket

cout << "\nSorry. That seat has been sold.\n";
}

// total clients
totalclients=totalclients++;
//total one user
totaltixcust=price[row-1];
//accumulate grand total price
totaltix=totaltix+totaltixcust;

cout << "\nWould you like to purchase another seat (y/n)? ";
cin >>otherSeat;


}
cout << "\n\nYou have purchased a total of " << totalclients << " tickets " << "for a total price of $" << totaltix;


}



void main_Menu()
{
int choice= 0;
while(choice!= 5)
{

cout << "\n\n\n\t\tC++ Theatre" << endl << endl;
cout << "\n\t1. View Available Seats";
cout << "\n\t2. View Seating Prices";
cout << "\n\t3. View Ticket Sales";
cout << "\n\t4. Purchase a Ticket";
cout << "\n\t5. Exit the Program\n\n";
cout << "\n\tEnter your choice(1-5): ";
cin>>choice;

while(choice <= 0 || choice > 5)
{
cout << "Choice must be between 1 and 5. Please re-enter: ";
cin>>choice;

}
switch (choice)
{
case 1:
showChart(seat);
//show seating chart
break;
case 2:
showPrice(price, x);
//view seating price
break;
case 3:
cout << "\n\nTotal Sales to Date: $" << totaltix << "\n\n";
//view total ticket sale for all clients
break;
case 4:
tixPurchase();
//purchase ticket
break;
case 5:
//quit program
break;
//default: cout << "default\n";
}

}
}




Please post your code inside the code tags.
Simply select all your code and click on the <> button.
Topic archived. No new replies allowed.