Please help – I am having either some logic issues or formatting issues:

My code is the following:

#include <iostream>
using std::cout; 
using std::cin;
using std::endl;

#include <iomanip>
using std::setw;
using std::setprecision;						


#include <cstdlib> // contains prototypes for functions srand and rand
using std::rand;
using std::srand;

#include <ctime> // contains prototype for function time
using std::time;

#include "Tickets.h"	// include definition of class Tickets


//constructor
Tickets::Tickets(int initial)
{
	// initialize the prices array
	int price = 90;
	for (int zone = 1; zone < row; zone++)
	{	
		prices[zone] = price;
		price -= 5;
	}

	// initialize the actual seating array
                for(int eachRow = 0; eachRow < row; eachRow++)
	    for(int eachSeat = 0; eachSeat < seat; eachSeat++)
		seating[eachRow][eachSeat] = '#';

	// initialize the available rows array
	for(int row_i = 1; row_i < row; row_i++)
		rowSeats[row_i] = seat - 1;

	qty = initial;
	ticketPrice = initial;
	totalPrice = initial;
	currentSalesAmount = initial;
	seatsSold = initial;
	theaterAvailability = (row-1)*(seat-1);		
}

void Tickets::displaySeats()
{
	// creater the header
	cout << "Seats: " << setw(2);
	int counter = 1;
	do
	{
	    if(counter <= 9)
	          cout << counter << setw(2);
	    else
	          cout << counter << setw(1);
	}while(++counter <= 30);

	// show the seat availability
	for(int row_i = 1; row_i < row; row_i++)
	{
	    if(row_i <= 9)
	    {
	        cout << "\nrow 0" << row_i << ": ";
                    }
	     else
	     {
		cout << "\nrow " << row_i << ": ";
                     }

	         for (int seat_j = 1; seat_j < seat; seat_j++)
	                 cout << seating[row_i][seat_j] << " ";
	  }
	cout << endl;
}

void Tickets::purchaseTickets()
{
	srand ( (unsigned)time ( 0 ) );	
	
	int counter = rand() % (row - 6);		

	do
	{
		qty = rand() % (seat-21); 
		while(qty == 0)
		{
		  qty = rand() % (seat-21); 
		}
		cout << "\nEnter the ticket quantity: " << qty;
		// validateQty(qty);

		if(theaterAvailability != 0)
		{
			seatProcess();
			totalPrice = 0;
		}
	}while(--counter > 0);
}

void Tickets::seatProcess()
{
	if(checkQtyAvailability(qty) == true)
	{
		if(qty == 1)
		{
			makeSelection();
		}
		else
		{
			//displayOptions();

			for(int choices = qty; choices > 0; choices--)
			{
				makeSelection();
			}
		}
	} // end if

	displayTotalTicketPrices();
	displayTheaterStats();
	displaySeats();
}

void Tickets::makeSelection()
{
	int selectedRow, selectedSeat;
	selectedRow = rand() % row;	
	while(selectedRow == 0)
	{
		selectedRow = rand() % row;	
	}
	cout << "\nSelect a row: " << selectedRow << endl;
	selectedSeat = rand() % seat; 
		while(selectedSeat == 0)
	{
		selectedRow = rand() % row;	
	}
	cout << "Select a seat: " << selectedSeat << endl;	

	validateSelection(selectedRow, selectedSeat);
}

void Tickets::validateSelection(int chosenRow, int chosenSeat)
{
	if(seating[chosenRow][chosenSeat] == '*')
	{
		cout << "Sorry that seat is taken. Please make another selection.";
		makeSelection();
	}
	else 
	{
		seating[chosenRow][chosenSeat] = '*';
		displayTicketPrice(chosenRow);
		compute(chosenRow);
	}	
}

bool Tickets::checkQtyAvailability(int desiredQty)
{
	bool answer = false;

	if (theaterAvailability == 0)
	{
		cout << "Sorry the theater is sold out." << endl;
		answer = false;
	}
	else if(theaterAvailability >= desiredQty)
		answer = true;
	else if(theaterAvailability < desiredQty)
	{
		qty = rand() % seat;
		while(qty == 0)
		{
			qty = rand() % seat;
		}
		cout << "Sorry there are less seats available then the quantity entered. \n Re-enter the ticket quantity: " << qty;
		// validateQty(qty);
		seatProcess();
	}
	return answer;
}

void Tickets::compute(int purchasedRow)
{
	//totalPrice += prices[purchasedRow];
	//currentSalesAmount += prices[purchasedRow];

	totalPrice += ticketPrice;
	currentSalesAmount += ticketPrice;
	seatsSold++;
	theaterAvailability--;
	rowSeats[purchasedRow]--;
}

double Tickets::getTotalPrice()
{
	return totalPrice;
}
double Tickets::getCurrentSalesAmount()
{
	return currentSalesAmount;
}

void Tickets::displayTicketPrice(int purchasedSeat)
{
	ticketPrice = prices[purchasedSeat];
	cout << "The purchased ticket price is: $" << setprecision(2) << ticketPrice << endl;
}

void Tickets::displayTotalTicketPrices()
{
	cout << "\nYour total amount due for the " << qty << " tickets is: $" << setprecision(2) << getTotalPrice() << endl;
}

void Tickets::displayTheaterStats()
{
	cout << "\nCurrent ticket sales amount: $" << setprecision(2) << getCurrentSalesAmount() << endl;
	cout << "Seats sold: " << seatsSold << endl;
	cout << "\n Row" << setw(22) << "Seats Available" << endl;
	cout << "-------       --------------" << endl;

	for(int rowAnalysis = 1; rowAnalysis < row; rowAnalysis++)
		cout << setw(4) << rowAnalysis << setw(17) << rowSeats[rowAnalysis] << endl;

	cout << "Seats available in the entire theater: " << theaterAvailability << endl;
	cout << endl;
}

void Tickets::displayOptions()
{
cout << "\nThe following blocks are available: " << endl;

for(int openRow = 1; openRow < row; openRow++)
{
  cout << "row " << openRow << ": ";
  for(int openSeat = 1; openSeat < seat; openSeat++)
 {
     int neededSeatsOpen = (seat-1) - (openSeat - 1);
     if(neededSeatsOpen >= qty)
     {
           int counter2 = 0;				
           for(int potential = qty - 1; potential >= 0; potential--)
          {
	if(char(seating[openSeat + potential]) == '#')
	{
	   counter2++;
	}
          }

          if(counter2 == qty)
          {
	for(int available = 0; available <= qty - 1; available++)
	{
	   cout << seating[openSeat + available] << " ";
	}
          }
      }
  }
}
} // end function display Options

bool Theater::test()
{
	Tickets testTicket(0);

	bool answer2 = false;
	if(testTicket.prices[9] == 50)
	{
		answer2 = true;
	}
	else
	{
		answer2 = false;
	}

	return answer2;
}

Here' is an example of the output I am getting. As you can see total amount due and current ticket sales is not printing correctly. (these are the variables totalPrice and currentSalesAmount). I cannot see what the issue is with the debugger so I do not know what is going on.

example of output, sad face by the problem:

Seats: 1 2 3 4 5 6 7 8 9101112131415161718192021222324252627282930
row 01: # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
row 02: # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
row 03: # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
row 04: # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
row 05: # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
row 06: # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
row 07: # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
row 08: # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
row 09: # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
row 10: # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
row 11: # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
row 12: # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
row 13: # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
row 14: # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
row 15: # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

Enter the ticket quantity: 2
Select a row: 13
Select a seat: 8
The purchased ticket price is: $30

Select a row: 15
Select a seat: 23
The purchased ticket price is: $20

Your total amount due for the 2 tickets is: $50

Current ticket sales amount: $50
Seats sold: 2

Row Seats Available
------- --------------
1 30
2 30
3 30
4 30
5 30
6 30
7 30
8 30
9 30
10 30
11 30
12 30
13 29
14 30
15 29
Seats available in the entire theater: 448

Seats: 1 2 3 4 5 6 7 8 9101112131415161718192021222324252627282930
row 01: # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
row 02: # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
row 03: # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
row 04: # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
row 05: # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
row 06: # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
row 07: # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
row 08: # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
row 09: # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
row 10: # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
row 11: # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
row 12: # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
row 13: # # # # # # # * # # # # # # # # # # # # # # # # # # # # # #
row 14: # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
row 15: # # # # # # # # # # # # # # # # # # # # # # * # # # # # # #

Enter the ticket quantity: 3
Select a row: 3
Select a seat: 10
The purchased ticket price is: $80

Select a row: 10
Select a seat: 5
The purchased ticket price is: $45

Select a row: 12
Select a seat: 16
The purchased ticket price is: $35

Your total amount due for the 3 tickets is: $1.6e+002 :'(

Current ticket sales amount: $2.1e+002 :'(
Seats sold: 5

Row Seats Available
------- --------------
1 30
2 30
3 29
4 30
5 30
6 30
7 30
8 30
9 30
10 29
11 30
12 29
13 29
14 30
15 29
Seats available in the entire theater: 445

Seats: 1 2 3 4 5 6 7 8 9101112131415161718192021222324252627282930
row 01: # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
row 02: # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
row 03: # # # # # # # # # * # # # # # # # # # # # # # # # # # # # #
row 04: # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
row 05: # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
row 06: # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
row 07: # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
row 08: # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
row 09: # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
row 10: # # # # * # # # # # # # # # # # # # # # # # # # # # # # # #
row 11: # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
row 12: # # # # # # # # # # # # # # # * # # # # # # # # # # # # # #
row 13: # # # # # # # * # # # # # # # # # # # # # # # # # # # # # #
row 14: # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
row 15: # # # # # # # # # # # # # # # # # # # # # # * # # # # # # #

Theater program successful.

Press any key to continue . . .

How much longer is the code if you include main and the .h file? We can't compile and run it without them so you might want to post them too. Thanks.

How much longer is the code if you include main and the .h file? We can't compile and run it without them so you might want to post them too. Thanks.

It's ok I figured it out.

For all of them it was a formatting issue that only needed:

<< setprecision(2) << showpoint << fixed <<
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.