Project: Save and Load Balance

Add a save/load option using file I/O for saving the balance in a file balance.txt.

Project: Save and Load Balance

Add a save/load option using file I/O for saving the balance in a file balance.txt.

#include <iostream>
using namespace std;

int main() {
    int balance = 100;
    int choice;
    
    // Add code for file I/O here
    
    // Make the required changes in the do-while loop too

    do {
        cout << "\n1. View Balance\n2. Deposit\n3. Withdraw\n4. Exit\n> ";
        cin >> choice;

        switch (choice) {
            case 1:
                cout << "Balance: $" << balance << endl;
                break;
            case 2: {
                int deposit;
                cout << "Deposit amount: ";
                cin >> deposit;
                balance += deposit;
                break;
            }
            case 3: {
                int withdraw;
                cout << "Withdraw amount: ";
                cin >> withdraw;
                if (withdraw <= balance) {
                    balance -= withdraw;
                } else {
                    cout << "Insufficient funds!" << endl;
                }
                break;
            }
        }
    } while (choice != 4);

    return 0;
}
Update the ATM with file I/O