Drill

ProblemsC++ › finance

Variance from budget

easyfinanceMathC++

A ledger compares what was planned against what actually happened: report the signed difference.

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.

Solve it in Python →

Where you start

int budgetVariance(int budget, int actual) {
    
}

Worked examples

CallResult
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++
int budgetVariance(int budget, int actual) {
    return actual - budget;
}

The same problem in another language

More finance problems in C++