All courses / Data Structures and Algorithms for Game Devs / Bits and bytes

Spot the bug: the gold total

Challenge lesson, about 10 min, +20 XP

The tower shop asked an AI assistant for a sales report: the total gold and the average sale, for tonight and for the whole season. The assistant wrote it, tried it on a few nights of sales, and every number came out right. Then the season report printed a negative total. A shop cannot take in less than nothing.

This bug does not sit on one wrong line. Every line does what it says. The flaw is a choice made before any line was written: the type that holds the total. To find this kind of bug, you ask a question the tests never asked.

Read the rest of this lesson and run the code in your browser.

Previous: Under the hood: the level 256 glitch   Next: How much memory a map needs

© 2026 Xero Media LLC. All rights reserved.