Simple Bank Account Transaction Tracker
Build a basic C++ program that tracks deposits and withdrawals for a single bank account and displays the final balance.
Challenge prompt
Create a C++ program that allows a user to input a series of transactions to a bank account. Each transaction will either be a deposit or a withdrawal. Your program should keep track of the current balance starting from zero, apply each transaction, and then display the final balance after all transactions have been processed. The program should stop taking input when the user enters 0 as the transaction amount.
Guidance
- • Use a loop to continuously take input until the user enters 0.
- • Use conditionals to differentiate between deposits (positive numbers) and withdrawals (negative numbers).
- • Keep track of the balance as you process each transaction.
Hints
- • Remember to initialize the balance variable to zero before starting the loop.
- • You can use an integer variable to read the transaction amount from user input.
- • Add the transaction amount to the balance to update it after each entry.
Starter code
#include <iostream>
using namespace std;
int main() {
int balance = 0;
int transaction = -1; // initialize with a non-zero value to start the loop
// TODO: implement input loop and balance update
return 0;
}Expected output
Enter a transaction amount (0 to end): 100 Enter a transaction amount (0 to end): -50 Enter a transaction amount (0 to end): 25 Enter a transaction amount (0 to end): 0 Final balance: 75
Core concepts
Challenge a Friend
Send this duel to someone else and see if they can solve it.