Campbell Ritchie wrote:The website I asked about avoiding doesn’t come up. I shall try to edit your post, because I think there is a spelling error in the link.
There are people who take programming courses because they want to program and people who think they have to as a part of a larger course. But you might as well get the best mark you can.
You achieve two things by banging your head against a keyboard. A damaged computer and a headache.
If you stepped back and got a piece of paper and wrote something like this on it, you would see what I meant by starting at No 2.You have to put it in code tags on this website to get the numbers aligned. If you stepped back and worked out the algorithm, you could work out the workings of your array in a few minutes. And you could avoid getting annoyed with yourself and everybody else.
Fred, Bear and Dennis are right.
It is quicker to start from scratch, working out the algorithm, than to tinker with code which nearly works. I was very brief about the 2 and -2, and you ought to have asked for more explanation rather than guessing what I meant. You can guess a million times, and your code looks as if you are guessing. Within those million you will find something which works. Or you can work it out, which means paper pencil and eraser (the latter being the most important). And get it right first time. And get elegant code.
When I say paper and pencil I mean paper and pencil. Turn your PC off. You can turn it on when you have worked out the algorithm and see it work
Campbell Ritchie wrote: - 2 and start with index 2.
Campbell Ritchie wrote:Please tell us where you found that info, so we can avoid that site!.
Campbell Ritchie wrote:Another problem about what Henry calls “colour by numbers” is that you don’t know when something would be better done otherwise. Because you are told to use protected fields, for example, you never learn how much better private fields would have been.