There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
fred rosenberger wrote:First, break the problem down into small chunks. various things you need to do:
print numbers
get input from users
check if a number is odd or even
loop over a range of numbers
print three numbers on a line
These become lego bricks you use to build your program. If any of these are too complicated - like printing three numbers on a line - break it down further. What you need to do for that would be something like
print a number
print a newline
count how many numbers have been printed
reset how many numbers have been printed
figure out if something has happened three times.
again, these become lego bricks you use to build the last lego brick in my first list...
you only try and do one at a time, and make sure it works, before you do the next.
Kasha Blair wrote:It's a very frustrating course since the instructor creates assignments that require knowledge of concepts we have not yet learned.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Stephen Black wrote:The bitwise operator can solve the problem
if ((number & 1)==1)
{
// It's odd
}
Matthew Brown wrote:
Stephen Black wrote:The bitwise operator can solve the problem
if ((number & 1)==1)
You can do that, but it's a method that will be less familiar to most people, especially beginners. I'd suggest if (number % 2 == 1)
Don't get me started about those stupid light bulbs. |