AMD Construction Group's equipment-tracking tool keeps a running budget deficit as a signed value and compares it against an unsigned remaining-budget figure pulled from the accounting system. On a typical two's-complement platform (effectively every modern machine this runs on), this snippet doesn't print what most people expect on first read.
#include <stdio.h>
int main(void) {
int deficit = -5;
unsigned int budget = 10;
if (deficit < budget) {
printf("under budget
");
} else {
printf("over budget
");
}
int diff = budget - 20;
printf("diff: %d
", diff);
return 0;
}
What exactly gets printed, and why? Then explain what you would change so the comparison behaves the way it looks like it should at a glance.
For grading, implement analyze_budget_types(bits) and return the typical output, the language-level caveat, and a safe correction.
def analyze_budget_types(bits):