Help I am having the following error:
error C2446: '==' : no conversion from 'int' to 'char *'

When I tried the following it ignores my counter and I am not sure why. This is a serious problem because it creates and infinite loop that keeps printing.

if(char(seating[openSeat + potential]) == '#')
      counter2++;

My code is the following:

void Tickets::displayOptions()
{
cout << "The 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 if
} // nested end for
}// end for
} // end function display Options

Why the cast to type char regarding the variable seating[]? Or in otherwords, seating is an array of what type?

Why the cast to type char regarding the variable seating[]? Or in otherwords, seating is an array of what type?

seating is an array of type char

If seating is an array of char, then there is no need to cast seating[] to type char because seating [] is a char.

I don't see where you are trying to equate an int with a char pointer or char array, though I've never tried to cast a variable to it's own type to know what would happen. If dropping the cast to type char doesn't work then trying to isolate the error some other way will be needed for me to be of help.

I do know that this isn't doing what you want:

if(counter2 = qty)

That should be the equal operator, not the asssignment operator.

The compiler believes that seating is an integer. The OP placed the cast there to try to get rid of the error message.

Can we see the class definition where seating is declared? Is there anything else between the class and the variable? Did you #include the header in the .cpp file?

Hope this helps.

If seating is an array of char, then there is no need to cast seating[] to type char because seating [] is a char.

I don't see where you are trying to equate an int with a char pointer or char array, though I've never tried to cast a variable to it's own type to know what would happen. If dropping the cast to type char doesn't work then trying to isolate the error some other way will be needed for me to be of help.

I do know that this isn't doing what you want:

if(counter2 = qty)

That should be the equal operator, not the asssignment operator.

thank you - I did not even catch that.

The compiler believes that seating is an integer. The OP placed the cast there to try to get rid of the error message.

Can we see the class definition where seating is declared? Is there anything else between the class and the variable? Did you #include the header in the .cpp file?

Hope this helps.

Sure - below is my entire code. Where I actually call the displayOptions() function I commented out so I could work with my other functions.
Basically if I do not use the cast char to convert it and only use this:

if(seating[openSeat + potential] == '#')
{
     counter2++;
}

I get the following error:
.cpp(259) : error C2446: '==' : no conversion from 'int' to 'char *'
.cpp(259) : error C2040: '==' : 'char [31]' differs in levels of indirection from 'int'

Hence I left my code as with the char but there is still something strange going on in that displayOptions() function that produces garbage and that is why I cannot use my function.

Please help. 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;
}

Also, below is my header file:

class Tickets
{
public:
	const static int row = 16;
	const static int seat = 31;

	double prices[row];
	char seating[row][seat];
	int rowSeats[seat];

	Tickets(int);		//constructor

	void displaySeats();
	void purchaseTickets();

	void compute(int);
	void displayTotalTicketPrices();
	void displayTicketPrice(int);
	void displayTheaterStats();
	// void validateQty(int);

	void seatProcess();
	bool checkQtyAvailability(int);
	void makeSelection();
	void validateSelection(int, int);
	void displayOptions();

	double getTotalPrice();
	double getCurrentSalesAmount();
private:
	int qty;
	double ticketPrice;
	double totalPrice;
	double currentSalesAmount;
	int seatsSold;
	int theaterAvailability;

};

class Theater
{
public:
	static bool test();
};

Ah, it is because seating is declared as a 2D array, but you are only indexing one dimension. Hence the error.

Did you mean to treat seating as a 1D array in your function? I'm not sure how you are trying to index the seating array in your function...

If I am reading it right (from just a quick glance over your code) it should be: if(seating[openRow][openSeat + potential] == '#') Hope this helps.

Ah, it is because seating is declared as a 2D array, but you are only indexing one dimension. Hence the error.

Did you mean to treat seating as a 1D array in your function? I'm not sure how you are trying to index the seating array in your function...

If I am reading it right (from just a quick glance over your code) it should be: if(seating[openRow][openSeat + potential] == '#') Hope this helps.

Thanks@! I hate when I spend so much time trying to fix code and it turns out to be something that should have been so obvious.

Thanks again :)

I know what you mean. When I was first learning C I spent three or four days once trying to figure out an error -- which turned out to be a missing } in an #included file...

An extra pair of eyes if always useful for these kinds of things.

:)

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.