Variance from budget
A ledger compares what was planned against what actually happened: report the signed difference.
- Variance is actual minus budget.
- The result keeps its sign — overspend is positive, underspend negative.
BudgetVariance(budget: int, actual: int) → int
C# needs a compiler and Drill does not host one yet, so this page is the reference rather than an exercise: the problem, worked examples, and the solution in full. To type it out, the same problem runs in Python.
Where you start
public int BudgetVariance(int budget, int actual) {
}
Worked examples
| Call | Result |
|---|---|
BudgetVariance(100, 120) | 20 |
BudgetVariance(100, 90) | -10 |
BudgetVariance(0, 0) | 0 |
BudgetVariance(50, 50) | 0 |
Hint
Subtract budget from actual.
Reference solution in C#
public int BudgetVariance(int budget, int actual) {
return actual - budget;
}