cppbeginner10 minutes

Simple Budget Tracker: Track Expenses and Calculate Balance

Create a beginner-friendly console program in C++ that allows users to input their income and a list of expenses, then calculates and displays the remaining balance.

Challenge prompt

Write a C++ program that asks the user to enter their total income as a double, then prompts for the number of expense items. Allow the user to input each expense amount. Finally, calculate and display the total expenses and the remaining balance after subtracting expenses from income.

Guidance

  • Use variables to store income, expenses, total expenses, and balance.
  • Use a loop to input multiple expense amounts and calculate their sum.
  • Display results with clear formatting to the user.

Hints

  • You can use a for loop to iterate through the number of expenses.
  • Make sure to use double type variables to handle currency values with decimal points.
  • Use simple arithmetic operations to sum expenses and calculate balance.

Starter code

#include <iostream>
using namespace std;

int main() {
    double income, expense, totalExpenses = 0;
    int expenseCount;

    cout << "Enter your total income: ";
    cin >> income;

    cout << "How many expenses do you have? ";
    cin >> expenseCount;

    for (int i = 0; i < expenseCount; i++) {
        cout << "Enter expense #" << (i + 1) << ": ";
        // Input expense here and add to totalExpenses
    }

    // Calculate and display total expenses and remaining balance

    return 0;
}

Expected output

Enter your total income: 2000 How many expenses do you have? 3 Enter expense #1: 300.50 Enter expense #2: 150 Enter expense #3: 100 Total expenses: 550.5 Remaining balance: 1449.5

Core concepts

variablesloopsinput/outputarithmetic operations

Challenge a Friend

Send this duel to someone else and see if they can solve it.