Balancing Accounts

Difficulty: Medium

Your bank receives two deposits or credits and three bills or debits. The credits cover the debits, meaning that your balance should never go below zero, but the bank has clever software: The bills are calculated first, which thrusts your account into negative territory complete with fees — even though the deposits cover the bills. Is this obnoxious behavior the result of greedy bankers or clever programming?
Continue reading

Positive, Negative, or Zero

The strcmp() function returns a value based on the comparison of two strings. The value is zero when the strings match, otherwise the value is positive or negative depending on how the strings compare. This result makes me wonder which other functions can return positive, negative, or zero values and whether the C library has a sign() function or similar that helps make such a determination.
Continue reading

Some Weighty Conversions

The three units of weight I’m familiar with are pounds, kilograms, and stone. For me, stone is the odd one. I’ve heard it used in Britain and it’s completely baffling to me, often requiring that I whip out a calculator to see what “14 stone” really means. Better, I could write code that converts between pounds, kilograms, and stone, which is the goal of this month’s Exercise.
Continue reading

Spelling Numbers

I would guess that most beginning programmers can deftly craft a loop that outputs sequential integer values, say from 0 to 100. In fact, this is the type of code I write whenever I learn a new language. I asked myself, “Can I write a loop to output values 0 to 100?” Usually in no time, I’ve constructed such a program. Simple.
Continue reading