error C2446: '==' : no conversion from 'int' to 'char *'

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: May 2008
Posts: 96
Reputation: QuantNeeds is an unknown quantity at this point 
Solved Threads: 0
QuantNeeds QuantNeeds is offline Offline
Junior Poster in Training

error C2446: '==' : no conversion from 'int' to 'char *'

 
0
  #1
Jul 7th, 2008
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.

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

My code is the following:

  1. void Tickets::displayOptions()
  2. {
  3. cout << "The following blocks are available: " << endl;
  4.  
  5. for(int openRow = 1; openRow < row; openRow++)
  6. {
  7. cout << "row " << openRow << ": ";
  8. for(int openSeat = 1; openSeat < seat; openSeat++)
  9. {
  10. int neededSeatsOpen = (seat-1) - (openSeat - 1);
  11. if(neededSeatsOpen >= qty)
  12. {
  13. int counter2 = 0;
  14. for(int potential = qty - 1; potential >= 0; potential--)
  15. {
  16. if(char(seating[openSeat + potential]) == '#')
  17. {
  18. counter2++;
  19. }
  20. }
  21. if(counter2 = qty)
  22. {
  23. for(int available = 0; available <= qty - 1; available++)
  24. {
  25. cout << seating[openSeat + available] << " ";
  26. }
  27. }
  28. } // end if
  29. } // nested end for
  30. }// end for
  31. } // end function display Options
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1,681
Reputation: Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all 
Solved Threads: 264
Lerner Lerner is offline Offline
Posting Virtuoso

Re: error C2446: '==' : no conversion from 'int' to 'char *'

 
0
  #2
Jul 7th, 2008
Why the cast to type char regarding the variable seating[]? Or in otherwords, seating is an array of what type?
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 96
Reputation: QuantNeeds is an unknown quantity at this point 
Solved Threads: 0
QuantNeeds QuantNeeds is offline Offline
Junior Poster in Training

Re: error C2446: '==' : no conversion from 'int' to 'char *'

 
0
  #3
Jul 7th, 2008
Originally Posted by Lerner View Post
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
Last edited by QuantNeeds; Jul 7th, 2008 at 5:13 pm.
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1,681
Reputation: Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all 
Solved Threads: 264
Lerner Lerner is offline Offline
Posting Virtuoso

Re: error C2446: '==' : no conversion from 'int' to 'char *'

 
0
  #4
Jul 7th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 1,951
Reputation: Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of 
Solved Threads: 214
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: error C2446: '==' : no conversion from 'int' to 'char *'

 
0
  #5
Jul 7th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 96
Reputation: QuantNeeds is an unknown quantity at this point 
Solved Threads: 0
QuantNeeds QuantNeeds is offline Offline
Junior Poster in Training

Re: error C2446: '==' : no conversion from 'int' to 'char *'

 
0
  #6
Jul 7th, 2008
Originally Posted by Lerner View Post
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.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 96
Reputation: QuantNeeds is an unknown quantity at this point 
Solved Threads: 0
QuantNeeds QuantNeeds is offline Offline
Junior Poster in Training

Re: error C2446: '==' : no conversion from 'int' to 'char *'

 
0
  #7
Jul 7th, 2008
Originally Posted by Duoas View Post
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:
  1. if(seating[openSeat + potential] == '#')
  2. {
  3. counter2++;
  4. }
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:

  1. #include <iostream>
  2. using std::cout;
  3. using std::cin;
  4. using std::endl;
  5.  
  6. #include <iomanip>
  7. using std::setw;
  8. using std::setprecision;
  9.  
  10.  
  11. #include <cstdlib> // contains prototypes for functions srand and rand
  12. using std::rand;
  13. using std::srand;
  14.  
  15. #include <ctime> // contains prototype for function time
  16. using std::time;
  17.  
  18. #include "Tickets.h" // include definition of class Tickets
  19.  
  20.  
  21. //constructor
  22. Tickets::Tickets(int initial)
  23. {
  24. // initialize the prices array
  25. int price = 90;
  26. for (int zone = 1; zone < row; zone++)
  27. {
  28. prices[zone] = price;
  29. price -= 5;
  30. }
  31.  
  32. // initialize the actual seating array
  33. for(int eachRow = 0; eachRow < row; eachRow++)
  34. for(int eachSeat = 0; eachSeat < seat; eachSeat++)
  35. seating[eachRow][eachSeat] = '#';
  36.  
  37. // initialize the available rows array
  38. for(int row_i = 1; row_i < row; row_i++)
  39. rowSeats[row_i] = seat - 1;
  40.  
  41. qty = initial;
  42. ticketPrice = initial;
  43. totalPrice = initial;
  44. currentSalesAmount = initial;
  45. seatsSold = initial;
  46. theaterAvailability = (row-1)*(seat-1);
  47. }
  48.  
  49. void Tickets::displaySeats()
  50. {
  51. // creater the header
  52. cout << "Seats: " << setw(2);
  53. int counter = 1;
  54. do
  55. {
  56. if(counter <= 9)
  57. cout << counter << setw(2);
  58. else
  59. cout << counter << setw(1);
  60. }while(++counter <= 30);
  61.  
  62. // show the seat availability
  63. for(int row_i = 1; row_i < row; row_i++)
  64. {
  65. if(row_i <= 9)
  66. {
  67. cout << "\nrow 0" << row_i << ": ";
  68. }
  69. else
  70. {
  71. cout << "\nrow " << row_i << ": ";
  72. }
  73.  
  74. for (int seat_j = 1; seat_j < seat; seat_j++)
  75. cout << seating[row_i][seat_j] << " ";
  76. }
  77. cout << endl;
  78. }
  79.  
  80. void Tickets::purchaseTickets()
  81. {
  82. srand ( (unsigned)time ( 0 ) );
  83.  
  84. int counter = rand() % (row - 6);
  85.  
  86. do
  87. {
  88. qty = rand() % (seat-21);
  89. while(qty == 0)
  90. {
  91. qty = rand() % (seat-21);
  92. }
  93. cout << "\nEnter the ticket quantity: " << qty;
  94. // validateQty(qty);
  95.  
  96. if(theaterAvailability != 0)
  97. {
  98. seatProcess();
  99. totalPrice = 0;
  100. }
  101. }while(--counter > 0);
  102. }
  103.  
  104. void Tickets::seatProcess()
  105. {
  106. if(checkQtyAvailability(qty) == true)
  107. {
  108. if(qty == 1)
  109. {
  110. makeSelection();
  111. }
  112. else
  113. {
  114. //displayOptions();
  115.  
  116. for(int choices = qty; choices > 0; choices--)
  117. {
  118. makeSelection();
  119. }
  120. }
  121. } // end if
  122.  
  123. displayTotalTicketPrices();
  124. displayTheaterStats();
  125. displaySeats();
  126. }
  127.  
  128. void Tickets::makeSelection()
  129. {
  130. int selectedRow, selectedSeat;
  131. selectedRow = rand() % row;
  132. while(selectedRow == 0)
  133. {
  134. selectedRow = rand() % row;
  135. }
  136. cout << "\nSelect a row: " << selectedRow << endl;
  137. selectedSeat = rand() % seat;
  138. while(selectedSeat == 0)
  139. {
  140. selectedRow = rand() % row;
  141. }
  142. cout << "Select a seat: " << selectedSeat << endl;
  143.  
  144. validateSelection(selectedRow, selectedSeat);
  145. }
  146.  
  147. void Tickets::validateSelection(int chosenRow, int chosenSeat)
  148. {
  149. if(seating[chosenRow][chosenSeat] == '*')
  150. {
  151. cout << "Sorry that seat is taken. Please make another selection.";
  152. makeSelection();
  153. }
  154. else
  155. {
  156. seating[chosenRow][chosenSeat] = '*';
  157. displayTicketPrice(chosenRow);
  158. compute(chosenRow);
  159. }
  160. }
  161.  
  162. bool Tickets::checkQtyAvailability(int desiredQty)
  163. {
  164. bool answer = false;
  165.  
  166. if (theaterAvailability == 0)
  167. {
  168. cout << "Sorry the theater is sold out." << endl;
  169. answer = false;
  170. }
  171. else if(theaterAvailability >= desiredQty)
  172. answer = true;
  173. else if(theaterAvailability < desiredQty)
  174. {
  175. qty = rand() % seat;
  176. while(qty == 0)
  177. {
  178. qty = rand() % seat;
  179. }
  180. cout << "Sorry there are less seats available then the quantity entered. \n Re-enter the ticket quantity: " << qty;
  181. // validateQty(qty);
  182. seatProcess();
  183. }
  184. return answer;
  185. }
  186.  
  187. void Tickets::compute(int purchasedRow)
  188. {
  189. //totalPrice += prices[purchasedRow];
  190. //currentSalesAmount += prices[purchasedRow];
  191.  
  192. totalPrice += ticketPrice;
  193. currentSalesAmount += ticketPrice;
  194. seatsSold++;
  195. theaterAvailability--;
  196. rowSeats[purchasedRow]--;
  197. }
  198.  
  199. double Tickets::getTotalPrice()
  200. {
  201. return totalPrice;
  202. }
  203. double Tickets::getCurrentSalesAmount()
  204. {
  205. return currentSalesAmount;
  206. }
  207.  
  208. void Tickets::displayTicketPrice(int purchasedSeat)
  209. {
  210. ticketPrice = prices[purchasedSeat];
  211. cout << "The purchased ticket price is: $" << setprecision(2) << ticketPrice << endl;
  212. }
  213.  
  214. void Tickets::displayTotalTicketPrices()
  215. {
  216. cout << "\nYour total amount due for the " << qty << " tickets is: $" << setprecision(2) << getTotalPrice() << endl;
  217. }
  218.  
  219. void Tickets::displayTheaterStats()
  220. {
  221. cout << "\nCurrent ticket sales amount: $" << setprecision(2) << getCurrentSalesAmount() << endl;
  222. cout << "Seats sold: " << seatsSold << endl;
  223. cout << "\n Row" << setw(22) << "Seats Available" << endl;
  224. cout << "------- --------------" << endl;
  225.  
  226. for(int rowAnalysis = 1; rowAnalysis < row; rowAnalysis++)
  227. cout << setw(4) << rowAnalysis << setw(17) << rowSeats[rowAnalysis] << endl;
  228.  
  229. cout << "Seats available in the entire theater: " << theaterAvailability << endl;
  230. cout << endl;
  231. }
  232.  
  233. void Tickets::displayOptions()
  234. {
  235. cout << "\nThe following blocks are available: " << endl;
  236.  
  237. for(int openRow = 1; openRow < row; openRow++)
  238. {
  239. cout << "row " << openRow << ": ";
  240. for(int openSeat = 1; openSeat < seat; openSeat++)
  241. {
  242. int neededSeatsOpen = (seat-1) - (openSeat - 1);
  243. if(neededSeatsOpen >= qty)
  244. {
  245. int counter2 = 0;
  246. for(int potential = qty - 1; potential >= 0; potential--)
  247. {
  248. if(char(seating[openSeat + potential]) == '#')
  249. {
  250. counter2++;
  251. }
  252. }
  253.  
  254. if(counter2 == qty)
  255. {
  256. for(int available = 0; available <= qty - 1; available++)
  257. {
  258. cout << seating[openSeat + available] << " ";
  259. }
  260. }
  261. }
  262. }
  263. }
  264. } // end function display Options
  265.  
  266. bool Theater::test()
  267. {
  268. Tickets testTicket(0);
  269.  
  270. bool answer2 = false;
  271. if(testTicket.prices[9] == 50)
  272. {
  273. answer2 = true;
  274. }
  275. else
  276. {
  277. answer2 = false;
  278. }
  279.  
  280. return answer2;
  281. }

Also, below is my header file:

  1. class Tickets
  2. {
  3. public:
  4. const static int row = 16;
  5. const static int seat = 31;
  6.  
  7. double prices[row];
  8. char seating[row][seat];
  9. int rowSeats[seat];
  10.  
  11. Tickets(int); //constructor
  12.  
  13. void displaySeats();
  14. void purchaseTickets();
  15.  
  16. void compute(int);
  17. void displayTotalTicketPrices();
  18. void displayTicketPrice(int);
  19. void displayTheaterStats();
  20. // void validateQty(int);
  21.  
  22. void seatProcess();
  23. bool checkQtyAvailability(int);
  24. void makeSelection();
  25. void validateSelection(int, int);
  26. void displayOptions();
  27.  
  28. double getTotalPrice();
  29. double getCurrentSalesAmount();
  30. private:
  31. int qty;
  32. double ticketPrice;
  33. double totalPrice;
  34. double currentSalesAmount;
  35. int seatsSold;
  36. int theaterAvailability;
  37.  
  38. };
  39.  
  40. class Theater
  41. {
  42. public:
  43. static bool test();
  44. };
Last edited by QuantNeeds; Jul 7th, 2008 at 9:30 pm.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 1,951
Reputation: Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of 
Solved Threads: 214
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: error C2446: '==' : no conversion from 'int' to 'char *'

 
1
  #8
Jul 7th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 96
Reputation: QuantNeeds is an unknown quantity at this point 
Solved Threads: 0
QuantNeeds QuantNeeds is offline Offline
Junior Poster in Training

Re: error C2446: '==' : no conversion from 'int' to 'char *'

 
0
  #9
Jul 7th, 2008
Originally Posted by Duoas View Post
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
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 1,951
Reputation: Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of 
Solved Threads: 214
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: error C2446: '==' : no conversion from 'int' to 'char *'

 
0
  #10
Jul 7th, 2008
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.

Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC