Twenty-eight problems where a program has to decide something: the sign of a number, whether it divides, which season a month is in, how many of three numbers are positive, which squares a chess piece can reach. They are in order of difficulty — the first fifteen are the core of the week, the rest are for when those are done.
Three habits that save most of the Wrong Answers here:
- Chain or separate? If exactly one answer can be right — one season, one
grade — use an
if/else ifchain. If several things can be true at once, use separateifs. - The edges. Test the value exactly on each boundary: the 0, the 100, the
last day of the month. That is where
>and>=part company. %for divisibility.n % k == 0meanskdividesn;n % 2 == 0means even.
Some of these need the smallest or largest of a few numbers — the pattern from the lesson.