3 Replies - 593 Views - Last Post: 13 May 2013 - 03:05 AM Rate Topic: -----

#1 gs_90  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 12-May 13

theater seating question

Posted 12 May 2013 - 11:09 AM

Right now i am stuck. I am having a hard time trying to figure out how to get the sum for the tickets that are being bought in my program. If anyone can help, it would be great !! Thanks :bigsmile:/>/>

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

int main()
{
	const int PRICE = 5;
	int cost[PRICE], choice, ROW, COLUMN,
		ticket, seat, sum;
	const int row = 5, column = 10;
	const char full = '*';
	const char empty = '#';
	char seats[row][column];

	cout << "Guadalupe Sanchez\n";
	for(int count = 0; count < PRICE; count++)
	{
		cout << "Enter the price of Row " << (count + 1)
			<< ":" << endl;
		cin >> cost[count];

	}
	cout << "\t\tSeats\n";
	cout << "\t 1 2 3 4 5 6 7 8 9 10\n";

	for(int x = 1; x <= row; x++)
	{
		cout << "Row " << x;
		cout << "\t";
		for (int y = 1; y <= column; y++)
		{
			seats[row][column] = empty;
			cout << " " << seats[row][column];
		}
		cout << endl;
	}
	
	do 
	{
		cout << "1. Purchase a ticket or tickets.\n";
		cout << "2. View open seats.\n";
		cout << "3. View total of ticket sales.\n";
		cout << "4. Exit.\n";
		cout << "Please enter an option: ";
		cin >> choice;

		switch (choice)
		{
		case 1:
			do
			{ 
				cout << "How many tickets would you like to purchase?:\n";
				cin >> ticket;
				cout << "Which row would you like to sit?\n";
				cin >> ROW;	
				
				if(ticket > 1)
					cout << "What seats would you like?\n";
				else
					cout << "What seat would you like?\n";
				
				for(int count = 0; count < ticket; count++)
				{
					cout << "Enter seat in row:\n";
					cin >> seat;
				}
				if (seats[ROW][seat] == '*')
				{
					cout << "Seat is sold out. Please enter a new seat.\n";
				}
				else 
				{
					sum = 



This post has been edited by Atli: 12 May 2013 - 11:25 AM
Reason for edit:: Fixed the [code] ... [/code] tags.


Is This A Good Question/Topic? 0
  • +

Replies To: theater seating question

#2 tlhIn`toq  Icon User is online

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5675
  • View blog
  • Posts: 12,192
  • Joined: 02-June 10

Re: theater seating question

Posted 12 May 2013 - 11:57 AM

There is a VERY VERY common homework question.
We aren't going to fix your code for you.
"I can't make my homework work" is so vague we can't just fix it for you. The ability to design is as much a part of this homework as your ability to type the right code. Basic debugging would get you through this.


tlhIn`toq's FAQ list

Learning to debug one's own code is an essential skill. Sadly, one that apparently few college courses teach. Silly if you ask me.

Placing breakpoints and walking through the code line by line allows you to actually WATCH it execute.

Visualizing what your code does will let you see why it behaves the way it does.

It would be well worth your time to do the tutorials on FAQ 2. A couple hours learning this skill will save you hundreds of hours of confusion in one project alone.


TOP most asked:
What does this error message mean?
FAQ 2: How do I debug
FAQ 3: How do I make Class1/Form1 talk to Class2/Form2


FAQ (Frequently Asked Questions - Updated Apr 2013
Spoiler



Was This Post Helpful? 0
  • +
  • -

#3 gs_90  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 12-May 13

Re: theater seating question

Posted 12 May 2013 - 08:55 PM

did some work. Accomplished a lot, but when I run the program & when I get to the question 'would you like to confirm your purchase?(y/n)' I type y then enter & it keeps looping like crazy.

int main()
{
	const int PRICE = 5;
	int cost[PRICE], choice, ROW,
		ticket, seat, sum, confirm, total = 0,
		chair = 50, seat2 = 0;
	const int row = 5, column = 10;
	const char full = '*';
	const char empty = '#';
	char seats[row][column];

	for(int count = 0; count < PRICE; count++)
	{
		cout << "Enter the price of Row " << (count + 1)
			<< ":" << endl;
		cin >> cost[count];

	}
	cout << "\t\tSeats\n";
	cout << "\t 1 2 3 4 5 6 7 8 9 10\n";

	for(int x = 1; x <= row; x++)
	{
		cout << "Row " << x;
		cout << "\t";
		for (int y = 1; y <= column; y++)
		{
			seats[row][column] = empty;
			cout << " " << seats[row][column];
		}
		cout << endl;
	}
	
	do 
	{
		cout << "1. Purchase a ticket or tickets.\n";
		cout << "2. View open seats.\n";
		cout << "3. View total of ticket sales.\n";
		cout << "4. Exit.\n";
		cout << "Please enter an option: ";
		cin >> choice;

		switch (choice)
		{
		case 1:
			do
			{ 
				cout << "How many tickets would you like to purchase?:\n";
				cin >> ticket;
				cout << "Which row would you like to sit?\n";
				cin >> ROW;	
				
				if(ticket > 1)
				{
					cout << "What seats would you like?\n";
					for(int count = 0; count < ticket; count++)
					{
					cout << "Enter seat in row:\n";
					cin >> seat;
					}
				}
				else
				{
					cout << "What seat would you like?\n";
					cin >> seat;
				}
				
				if (seats[ROW][seat] == '*')
				{
					cout << "Seat is sold out. Please enter a new seat.\n";
				}
				else 
				{
					sum = cost[ROW - 1] * ticket;
					total += cost[ROW - 1];
					cout << "The total ticket sales is: " << sum << endl;
					cout << "Would you like to confirm your purchase? (y/n):";
					cin >> confirm;
					chair = chair - confirm;
					seat2 += confirm;

					if(confirm == 'y')
					{
						cout << "Your purchase has been confirmed." << endl;
						seats[ROW - 1][seat - 1] = full;
					}
						cout << "Would you like to purchase another seat? (y/n)" << endl;
						cin >> confirm;
				}

			}while (confirm == 'Y');
			break;

		case 2:
			cout << "\t\tSeats\n";
			cout << "\t 1 2 3 4 5 6 7 8 9 10\n";
			for(int x = 1; x <= row; x++)
			{
				cout << "Row " << x;
				cout << "\t";
				for (int y = 1; y <= column; y++)
				{
				cout << " " << seats[x][y];
				}
			cout << endl;
			}
		}
	}while (choice !=5);

	return 0;
}


This post has been edited by JackOfAllTrades: 13 May 2013 - 03:04 AM
Reason for edit:: Fixed code tags

Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6107
  • View blog
  • Posts: 23,661
  • Joined: 23-August 08

Re: theater seating question

Posted 13 May 2013 - 03:05 AM

Explain what you are doing here.

cout << "Would you like to confirm your purchase? (y/n):";
cin >> confirm;
chair = chair - confirm;
seat2 += confirm;


You're getting y/n variable and using it as an integer?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1