John Matthews wrote:But if you do want to count the number of lines first, a simple way is to just read a character at a time using fgetc() until you hit EOF, incrementing your line count if the character is the end-of-line '\n' character. Then, after allocating you array, use rewind() to go back to the beginning of the file and read the numbers.
Campbell Ritchie wrote:Please put code tags round your submitted code; it is very difficult to read as it is.
Why are you using floats for money? Why are you using floats at all? Any floating‑point arithmetic has too much imprecision to use for money, and floats are far worse than doubles.
Stop thinking in terms of a 0.01¢ coin; it is a 1¢ coin, and then do all your arithmetic in integers so €1 counts as 100.
Your arithmetic looks very complicated. You can calculate the number of 200 coins (=2€) simply by dividing the money by 200. Similarly you can calculate the remainder with the remainder operator %. It only works reliably in integer arithmetic, and your values shouldn't be negative, so use unsigned instead of int numbers. That means you can't calculate change < 0, but have to test whether you have enough money to buy the tickets first.
Mike Simmons wrote:Sounds like you would need to show some code of exactly what you did.
Campbell Ritchie wrote:Please format your code correctly. Spaces around operators please, and declarations on their own line please. Line 4 is illegible, and the variable names are difficult to follow.
Please explain what you want to happen and what does happen, with examples to make the problem clear. Put some debugging instructions in, printing the value of the char and showing progress of the copying.
Please also put some instructions for the user; who knows what they are supposed to write?
Dave Tolls wrote:The decimal format was going to be my next suggestion.
For the other issue, your Cores class has not overridden the toString method and so uses the default toString from Object.
You'll need to override toString if you want your println call to output something from your Cores objects.