Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

you'd think this'd work but....

 
Richard Shelly
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it doesnt! (is anyone really surprised!?)

heres the deal, i have a class, with a integer variable called ticketCount.
ticketCount is in a loop to read from a file, and increment, thus counting the number of tickets. strangely, it seems this increment never happens. despite every other command in the loop working. (and no, its not commented out!)
 
Martin Simons
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Post your code. You are probably, in some way or another, short circuting
your loop (looping back to the top) before you ever get to your counter.
Or your counter is inside of an if/switch/whatever statement that never
gets accessed. But incrementing a variable inside of a loop definately
does work.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let me guess, you are using

counter = counter++;

If so, take a very close look at how the post increment operator works.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nice guess Ilja
I could guess some very strange things too, but prefer to wait for Richard to post his loop.
 
Richard Shelly
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



Ticket is simply a class that holds an int(ticket number), an int array(the lottery numbers), and a string(suburb in which it was bought).
 
Richard Shelly
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
its cool!! it works now!! booyah!!
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's cool. That would also be cool to tell us where your blunder is
 
Richard Shelly
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well, clearly, i redefined tickets in the constructor (possibly me just assuming Eclipse is smarter than me.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic