Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I am studying c++ and I need to make a seating chart program. This is not my code as I am studying it to see how each part works. I am interested in the seating chart. I have tried many different things to try and figure this out myself, I have come close, having the Full (*) mark in the right column but it is never in the correct row.
If I choose seat # 1 and Row # 1 it makes the mark on the chart at seat and row #2.
Again, I am not using this code, I just learn better when I test things and see how they all work.
Here is the code
#include "stdafx.h"
#include <iostream>
#include <iomanip>
using namespace std;
int Show_Menu();
void Show_Chart();
const char FULL = '*';
const char EMPTY = '#';
const int rows = 11;
const int columns = 10;
char map[rows][columns];
double price;
int total = 0;
int seat = 90;
int seat2 = 0;
int Quit = 1;
int main()
{
const int Num_Rows = 11;
double price[Num_Rows];
int row2, column2, cost;
int answer;
//I have this blocked out as I am testing the chart only
/* cout << "Please enter price for each row." << endl;
for (int count = 0; count < rows; count++)
{
cout << "Row # " << (count + 1) << ": ";
cin >> price[count];
}
*/
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < columns; j++)
map[i][j] = EMPTY;
}
int choice;
do
{
choice = Show_Menu();
switch (choice)
{
case 1:
cout << "View Seat Prices\n\n";
for (int count = 0; count < rows; count++)
{
cout << "The price for row " << (count + 1) << ": ";
cout << price[count] << endl;
}
break;
case 2:
cout << "Purchase a Ticket\n\n";
do
{
cout << "Please select the row you would like to sit in: ";
cin >> row2;
cout << "Please select the seat you would like to sit in: ";
cin >> column2;
if (map[row2][column2] == FULL)
{
cout << "Sorry that seat is sold-out, Please select a new
seat.";
cout << endl;
}
else
{
cost = price[row2] + 0;
total = total + cost;
cout << "That ticket costs: " << cost << endl;
cout << "Confirm Purchase? Enter (1 = YES / 2 = NO)";
cin >> answer;
if (answer == 1)
{
cout << "Your ticket purchase has been confirmed."
<< endl;
map[row2][column2] = FULL;
}
else if (answer == 2)
{
cout << "Would you like to look at another seat? (1 =
YES / 2 = NO)";
cout << endl;
cin >> Quit;
}
cout << "Would you like to look at another seat?(1 = YES / 2
= NO)";
cin >> Quit;
}
} while (Quit == 1);
break;
case 3:
cout << "View Available Seats\n\n";
Show_Chart();
break;
case 4:
cout << "Total ticket sales: " << total << ".\n\n";
break;
case 5:
cout << "quit\n";
break;
default: cout << "Error input\n";
}
} while (choice != 5);
return 0;
}
int Show_Menu()
{
int MenuChoice;
cout << endl << endl;
cout << " \tMAIN MENU\n";
cout << " 1. View Seat Prices.\n";
cout << " 2. Purchase a Ticket.\n";
cout << " 3. View Available Seats.\n";
cout << " 4. View Ticket Sales.\n";
cout << " 5. Quit the program.\n";
cout << "_____________________\n\n";
cout << "Please enter your choice: ";
cin >> MenuChoice;
cout << endl << endl;
return MenuChoice;
}
void Show_Chart()
{
cout << "Seats 1 2 3 4 5 6 7 8 9 ";
for (int row = 0; row < 10; row++)//rows
{
cout << endl << "Row " << (row + 1);
for (int columns = 0; columns < 9; columns++)
{
cout << " " << map[row][columns];
}
}
cout << endl;
}
If I choose seat # 1 and Row # 1 it makes the mark on the chart at
seat and row #2...
The problem is that arrays in C start with index 0, so the left most seat has index 0, not 1. Thus, if you enter 1 into row2, and write map[row2][column2] = FULL, then actually the second seat is marked.
A simple fix would be to write map[row2-1][column2-1]; but make sure that the user must not enter value 0 then.
Related
I am currently working on a sudoku game and I need help in adding a functionality that will make a value I input after selecting a row and column to flash red if wrong and green if correct
how do you make an input value flash green color when the right number is inputed by the user.
this is what my code look like for now.
if (randomize == 1)
{
for (int i = 0; i < 70; i++)
{
printGrid1();
cout << "Select row number: ";
cin >> row;
cout << endl;
cout << "Select column number: ";
cin >> col;
cout << endl;
cout << "Input Answer: ";
cin >> maybe;
cout << endl;
//Funtion to restart game
if ( col == 10|| row == 10 || answer ==10)
{
printTitle();
selectDifficulty();
}
//Check for out of bound cells
if (row > 9 ||col>9 ||row <1|| col<1)
{
cout << "This row or column is not in the Sudoku Board"<< endl;
}
answer = easyGuessNumGrid1Answer[row-1][col-1];
if (maybe != answer){
score = score - 5;
cout << "Your score is :" << score <<endl;
}
if (maybe == answer)
{
cout << "Good job! " << maybe << " was the right number. " << endl;
easyGuessNumGrid1[row-1][col-1] = answer;
i++;
}
else
{
cout << "incorrect, please try again..." << endl;
i--;
}
}}
Evening, I am looking for a way to get the program to continue on instead of exiting out after asking to press enter to continue. 1 I cannot use the list command because im calling function "seatingChart" in another function and having the list command sends me back into the menu. Any suggestions?
void seatingChart()
{
for(row = 0; SEATROWS > row; ++row) // Placeholder for '#'
for (seat = 0; SEATS > seat; ++seat) // Placeholder for '#'
theater[row][seat] = '#'; // Applying '#' to the chart
cout << "\n\t\tSeats";
cout << "\n 123456789012345678901234567890" << endl; //seat header
for (int row = 0; SEATROWS > row; ++row)
{ // Initializing 15 rows
cout << "\nRow " << setw(2) << row+1 << "\t";
for (int seat = 0; SEATS > seat; ++seat)
{ // Initializing 30 seats
cout << theater [row][seat];} //display seating chart
}
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();
}
}
Entire code below: I get the issue when I input "1" at the menu in order to display the seating chart.
#include <iostream>
#include <iomanip>
using namespace std;
void list();
void getPrices();
void viewSales();
void seatingChart();
void ticketSales();
const int ROWS = 15;
const int COLS = 2;
double price[ROWS][COLS];
const int SEATROWS = 15; //PAT
const int SEATS = 30;//PAT
char theater[SEATROWS][SEATS];//PAT
int row;//PAT
int seat;//PAT
const char TAKEN = '*';//seats taken
const char EMPTY = '#';//seats free
int main()
{
int x; // Loop counter
for (x=0; x<ROWS;x++)
{
cout << "Please enter ticket price for Row " << setw(2) << (x + 1) << ": ";
cin >> price[x][COLS];
}
list();
return 0;
}
void list()
{
int choice;
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>5 || choice<1)
{
cout<<"Choice must be between 1 and 5. Please re-enter:";
cin>>choice;
}
if (choice == 1)
seatingChart();
else if (choice == 2)
getPrices();
else if (choice == 3)
viewSales();
else if (choice == 4)
ticketSales();
}
void getPrices()
{
cout<<"\nTicket Prices By Row "<<endl;
cout<<" Row Price"<<endl;
cout<<" --- -----"<<endl;
for (int x= 0; x < ROWS; x++)
{
cout<<setw(8)<<x+1<<setw(10);
cout<<fixed<<showpoint<<setprecision(2)<<price[x][2]<<endl;
}
cout<<"\n\n\nPress the Enter key to continue.";
cin.ignore();
cin.get();
list();
}
void viewSales()
{
double sum=0;
cout<<"\n\nTotal Sales to Date: $"<<fixed<<showpoint<<setprecision(2)<<sum<<"\n\n";
list();
}
void seatingChart()
{
for(row = 0; SEATROWS > row; ++row) // Placeholder for '#'
for (seat = 0; SEATS > seat; ++seat) // Placeholder for '#'
theater[row][seat] = '#'; // Applying '#' to the chart
cout << "\n\t\tSeats";
cout << "\n 123456789012345678901234567890" << endl; //seat header
for (int row = 0; SEATROWS > row; ++row) { // Initializing 15 rows
cout << "\nRow " << setw(2) << row+1 << "\t";
for (int seat = 0; SEATS > seat; ++seat){ // Initializing 30 seats
cout << theater [row][seat];} //display seating chart
}
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 ticketSales()
{
//*********************DISPLAY SEATING**********************************//
int row;
int seat;
char showSeating;
char anotherTicket = 'N';
int tickets = 0;
double totalPrice = 0;
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 >> showSeating;
if (toupper(showSeating) == 'Y')
seatingChart();
/*------------------Working display and working taken------------------------------*/
do
{
cout << "\nPlease enter desired row number (1-" << ROWS << "): ";
cin >> row;
while (row < 1 || row > ROWS)
{
cout << "Row must be between 1 and " << ROWS << ". Please re-enter: ";
cin >> row;
}
cout << "\nPlease enter desired seat number (1-" << SEATS << "): ";
cin >> seat;
while (seat < 1 || seat > SEATS)
{
cout << "Seat must be between 1 and " << SEATS << ". Please re-enter: ";
cin >> seat;
}
row--; seat--; // row and seat indexing starts from 0
if(theater[row][seat] == TAKEN)
{
cout << "This seat is taken! Try another one. \n";
}
else{ // and if it is - sell the ticket
theater[row][seat]==TAKEN;
tickets++;
// Need to update seating chart upon purchase
totalPrice += price[row][COLS];
}
cout << "\nWould you like to purchase another seat (y/n)? ";
cin >> anotherTicket;
anotherTicket = toupper(anotherTicket);
}while (anotherTicket == 'Y');
cout << "\n\nYou have purchased a total of " << tickets << " tickets " << "for a total price of $" << totalPrice;
list();
}
Unless you wrap your entire menu code inside a loop and make the exit condition for this loop the user input(in your case typing 5 for exit) the program will terminate as soon as it returns from your seatingchart() function because the list() function will return to main(i.e seatingchart() returns to list() and list() will return to main() ). You should do something like this:
do
{
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>5 || choice<1)
{
cout<<"Choice must be between 1 and 5. Please re-enter:";
cin>>choice;
}
if (choice == 1)
seatingChart();
else if (choice == 2)
getPrices();
else if (choice == 3)
viewSales();
else if (choice == 4)
ticketSales();
else if (choice==5)//this is your exit condition
break;//will break out of the menu loop
}while(1);//the is your menu loop
By the way there are some logical errors in your code, see the comment that are given in the comment section and correct them.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
So I am working on a theater seating problem. The output of the program isn't lining up the way it should. I need help lining up the # and * with their proper columns. Also pressing Q to quit isn't working. Also, I need to figure out how to read the seating chart information from a file.If the file with the seating info does not exist yet, it means that all the seats are
empty. Whenever the program ends, the seating chart information should be stored in this file. Any other tips would also be helpful. Here is my code so far:
#include "stdafx.h"
# include <iostream>
# include <iomanip>
using namespace std;
void seats( double [] , int);
void mapSeats();
char movieMenu(char);
int main()
{
const int rowNum = (15.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 = 15;//number of rows
const int col = 20;//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 << "Q) Quit program" << 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 =='q'||selection=='Q')
{
cout << "Thank you for using the program." << endl;
}
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)
{
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 <20;k++) //loop to display nums 0 to 19
{
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;
}
Q to quit isn't working. Your logic is wrong
do
{
...
} while (selection !='q' && selection !='Q');
You carry on while the selection isn't 'q' and while the selection isn't 'Q'. Very common for newbies to get 'or' and 'and' mixed up.
Need help writing a program for class. Here were the posted instructions:
Step 1: The program should have a FUNCTION that displays a screen that shows which seats are available and which are taken. Seats that are taken should be represented by a # symbol and seats that are available should be represented by a * symbol. The first thing your program should do is initialize all of the seats to available (*) and display the seating chart. (HINT: The seating chart should be a two dimensional array.)
Step 2: Each row in the auditorium has a different ticket price. So tickets in row 0 may be 5.00 each and tickets in row 1 may be 10.00 each. Your program should have a FUNCTION that reads the ticket price of each row from an input file called prices.dat. The ticket price for each row should be stored in a one dimensional array.
Step 3: Your program should have variables tracking the total number of tickets sold and the total revenue for all tickets sold.
Step 4:
Your program should allow the user to sell tickets one at a time. The user should be able to sell as many tickets as they would like (you need a loop for this). Do this with some sort of prompt or menu asking the user if they would like to sell another ticket. Don’t forget to validate input data if you need to.
To allow the user to sell a ticket your program should have the user enter a row number and a seat number for the ticket they would like to sell. The program should do four things with this information:
It should check to see if the seat is available. If the seat is taken the program should not allow the user to sell the ticket. If this happens, print a message to the user saying the ticket is not available and prompt the user to see if they would like to sell another ticket.
If the seat is available the program should update the seating chart by putting a taken symbol (#) in that seat’s position in the chart.
The program should then look up the row price for the seat sold. Your program should have a variable tracking the total revenue, the price of the seat sold should be added to this total after each sale.
Your program should have a variable tracking the total tickets sold. The next thing your program should do when selling a ticket is update the total tickets sold.
Step 5: Once the user is finished selling tickets print out an updated seating chart followed by the total tickets sold and the total revenue generate from those tickets.
NOTE: You are required to use two arrays in this program, one for the seating chart and one to store the prices for each row. You are also required to use two functions: one to display the seating chart and one to read in the price per row data and store it in the array with the prices for each row in it. You may use other functions if you want to but they are not required.
Note: The test data file for this run: prices.txt
10
10
10
9
9
9
8
8
8
7
7
7
6
6
6
I am stuck on step two where it says:
"Your program should have a FUNCTION that reads the ticket price of each row from an input file called prices.dat. The ticket price for each row should be stored in a one dimensional array."
I have no idea on how to create input files or check them for that matter.
Here is my code so far. I stopped in my case '1' after checking for duplicate seats. How would I then match the row with the price I want to charge from a data file?
#include <iostream>
#include <iomanip>
#include <string>
#include <istream>
#include <fstream>
using namespace std;
const int numberOfRow = 15;
const int numberOfCol = 20;
void print(char matrix[][20], int numberOfRow, int numberOfCol);
int main()
{
char matrix[numberOfRow][numberOfCol], seat[numberOfRow][numberOfCol];
char option;
int i, j;
int row,col;
int ticketsold = 0;
bool another =true;
for(i = 0; i < numberOfRow; i++)
for(j = 0; j < numberOfCol; j++)
matrix[i][j] = '*';
while(another)
{
print( matrix, numberOfRow, numberOfCol );
cout << "\nMenu:\n";
cout << "1) Buy ticket\n";
cout << "2) Total sell and exit\n\n";
cout << "Enter your choice : ";
cin >> option;
cout << endl << endl;
switch (option)
{
case '1' :
{
cout << "Enter row: ";
cin >> row;
cout << "\nEnter seat: ";
cin >> col;
if( matrix[row][col] == '*')
{
matrix[row][col] = '#';
ticketsold++;
}
else
{
cout << "Invalid seat choice";
}
//total revenue
}
/*case '2' :
{
another=false;
}
default :
cout << "Invalid choice";*/
}
}
system("pause");
}
void print(char matrix[][20], int numberOfRow, int numberOfCol)
{
int row, col, i, j;
cout << "* Seats available\n";
cout << "# Reserved Seats\n";
cout << "Seats: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19" << endl;
for(i = 0; i < numberOfRow; i++)
{
cout << "Row" << setw(3) << i;
for(j=0; numberOfCol > j; j++)
cout << setw(3) << matrix[i][j];
cout << endl;
}
}
The below program is almost similar to your requirement, except reading input from file.
This program will read input from console (user has to key-in price for each row.)
Again, this is not exactly how you want, but I hope it will help you. If possible, soon I'll post another program which can read input from file.
#include <iostream>
#include <iomanip>
using namespace std;
int Show_Menu ();
void Show_Chart ();
const char FULL = '*';
const char EMPTY = '#';
const int rows = 15;
const int columns = 30;
char map [rows][columns];
double price;
int total = 0;
int seat = 450;
int seat2 = 0;
int Quit = 1;
int main ()
{
const int Num_Rows = 15;
int price [Num_Rows];
int row2, column2, cost;
int answer;
cout << "\t*********************************************************" << endl;
cout << "\t* *" << endl;
cout << "\t* Welcome to our small town Theater *" << endl;
cout << "\t* *" << endl;
cout << "\t*********************************************************" << endl;
cout << endl << endl;
for (int count = 0; count < rows; count++)
{
cout << "Please enter the price for row " << (count + 1) << ": ";
cin >> price [count];
}
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < columns; j++)
map [i][j] = EMPTY;
}
int choice;
do
{
choice = Show_Menu();
switch (choice)
{
case 1:
cout << "View Seat Prices\n\n";
for (int count = 0; count < rows; count++)
{
cout << "The price for row " << (count + 1) << ": ";
cout << price [count] << endl;
}
break;
case 2:
cout << "Purchase a Ticket\n\n";
do
{
cout << "Please select the row you would like to sit in: ";
cin >> row2;
cout << "Please select the seat you would like to sit in: ";
cin >> column2;
if (map [row2] [column2] == '*')
{
cout << "Sorry that seat is sold-out, Please select a new seat.";
cout << endl;
}
else
{
cost = price [row2] + 0;
total = total + cost;
cout << "That ticket costs: " << cost << endl;
cout << "Confirm Purchase? Enter (1 = YES / 2 = NO)";
cin >> answer;
seat = seat - answer;
seat2 += answer;
if (answer == 1)
{
cout << "Your ticket purchase has been confirmed." << endl;
map [row2][column2] = FULL;
}
else if (answer == 2)
{
cout << "Would you like to look at another seat? (1 = YES / 2 = NO)";
cout << endl;
cin >> Quit;
}
cout << "Would you like to look at another seat?(1 = YES / 2 = NO)";
cin >> Quit;
}
}
while (Quit == 1);
break;
case 3:
cout << "View Available Seats\n\n";
Show_Chart ();
break;
case 4:
cout << "Total ticket sales: "<<total<<".\n\n";
break;
case 5:
cout << "quit\n";
break;
default : cout << "Error input\n";
}
} while (choice != 5);
return 0;
}
//********************************************************************************
//********************************************************************************
//** **
//** Define Functions. **
//** **
//********************************************************************************
//********************************************************************************
int Show_Menu()
{
int MenuChoice;
cout << endl << endl;
cout << " \tMAIN MENU\n";
cout << " 1. View Seat Prices.\n";
cout << " 2. Purchase a Ticket.\n";
cout << " 3. View Available Seats.\n";
cout << " 4. View Ticket Sales.\n";
cout << " 5. Quit the program.\n";
cout << "_____________________\n\n";
cout << "Please enter your choice: ";
cin >> MenuChoice;
cout << endl << endl;
return MenuChoice;
}
void Show_Chart ()
{
cout << "\tSeats" << endl;
cout << " 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30\n";
for (int count = 0; count < 15; count++)
{
cout << endl << "Row " << (count + 1);
for (int count2 = 0; count2 < 30; count2++)
{
cout << " " << map [count] [count2];
}
}
cout << endl;
}
i was creating a seating program and i was wonder if there was a way to count the loops and place it in a variable. im trying to let the user know how many tickets he purchased
#include <iostream>
#include <iomanip>
#include <string>
#include <istream>
#include <fstream>
using namespace std;
const int numberOfRow = 15;
const int numberOfCol = 20;
void print(char matrix[][20],int numberOfRow, int numberOfCol);
int main()
{
ifstream datafile;
int i, j;
char matrix[numberOfRow][numberOfCol], seat[numberOfRow][numberOfCol];
char option;
int row, col, totalsold;
float totSold, temp,price = 0 , ticketprice[numberOfRow], totRevenue;
bool another = true;
string filename;
datafile.open("c:\\price.dat");
for(i=0;i<numberOfRow;++i)
{
datafile >> temp;
ticketprice[i]=temp;
cout<< "Row ";
cout<< setw(2)<< fixed << setprecision(2)<< i << setw(7) << ticketprice[i]<< endl;
}
for(i = 0; i< numberOfRow; i++)
for(j = 0; j< numberOfCol; j++)
matrix[i][j] = '*';
print(matrix,numberOfRow, numberOfCol);
while(another)
{
totalsold = 0;
totRevenue = 0;
cout << "Please enter the row you would like to sit in: " << endl;
cin >> row;
cout << "Please enter the column you would like to sit in: " << endl;
cin >> col;
cout << "would you like to purchase more tickets? <y,n>" << endl;
cin >> option;
matrix[row][col] = '#';
/*totRevenue = totRevenue + ticketprice[row];*/
if(option == 'y' || option == 'Y')
{
another = true;
}
else
{
another = false;
print(matrix,numberOfRow, numberOfCol);
totRevenue = totRevenue + ticketprice[row];
}
}
totRevenue = totRevenue + ticketprice[row];
cout << "Total Tickets Sold: " << endl;// << totSold << endl;
cout << "Total Revenue: $ " << fixed << setprecision(2)<< totRevenue<< endl;
cin >> i;
cin.get();
return 0;
}
void print(char matrix[][20],int numberOfRow, int numberOfCol)
{
int row, col, i, j;
cout << "seat: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19"<< endl;
for(i = 0; i < numberOfRow; i++)
{
cout << "row" << setw(3)<< i;
for(j = 0; numberOfCol > j; j++)
cout << setw(3) << matrix[i][j];
cout << endl;
}
}
If you want to count the number of tickets bought, you should define a variable that contain the number of bought tickets and increment it right after another = true;.
if(option == 'y' || option == 'Y')
{
another = true;
++totSold;
}
Are you sure about your while loop ?
Something like this, would make more sens:
//...
int totalsold = 0;
float totRevenue = 0.0;
while(another)
{
cout << "Please enter the row you would like to sit in: " << endl;
cin >> row;
cout << "Please enter the column you would like to sit in: " << endl;
cin >> col;
cout << "would you like to purchase more tickets? <y,n>" << endl;
cin >> option;
matrix[row][col] = '#';
++totalsold; // increment the number of tickets sold
totRevenue += ticketprice[row]; // increment to total price of the tickets
if(option == 'n' || option == 'N')
{
another = false; // exit the loop
}
}
print(matrix,numberOfRow, numberOfCol);
cout << "Total Tickets Sold: " << totalsold << endl;
cout << "Total Revenue: $ " << fixed << setprecision(2)<< totRevenue<< endl;
//...
However, there is plenty of strange things in the provided code. But the most important is to keep practicing, so keep playing with the code and those strange things will disappear like magic with experience ;)
I think what you're looking for is a line like:
totSold += 1;
immediately after assigning # to the arena layout.
Note that you should check if the seat is sold already or not before selling it again. :)