I am an absolute newbie to C++. I have an ATM program problem where I need to keep a running total of transactions and the balance of the checking account. I cannot think of how to set an accumulator for the transactions or how to keep a running total of the balance after each withdrawal and deposit. I added a static number to try to keep a running total of the transactions, this could be completely wrong but I wasn't sure what else to try. Thanks for all your help.
Below is the prompt and the code I've written so far:
Reorganize the program to implement functions to perform the main transactions of deposit or withdrawal as well as check balance, and exit. As this program executes each transaction you should allow the user to see the results of each transaction by displaying the following message:
“After your < Deposit/Withdrawal > your current balance is <insert current balance>”
At the end of the program modify the ending message to include the following:
“You have completed <insert number of transactions>
Your beginning balance was <Insert Initial Balance>
Your ending balance is <insert current balance>”
Note that calls to the check balance and the exit call do not count as transactions in the overall transaction count displayed at the end of the program.
#include <iostream>
#include <iomanip>
using namespace std;
void displayMenu ( );
void showStatic (); //Function for transaction accumulator
double depositBalance (double);
double withdrawalBalance (double);
int selection; //Choice option
double deposit, withdrawal, fdeposit, fwithdraw, amount;
double balance = 500.00;
int total = 0;
int main ()
{
cout << setprecision(2) << fixed << endl;
// Do while loop for menu selection
do
{
displayMenu ();
cout << "Which option would you like to select? " <<endl;
cin >> selection;
switch (selection)
{
case 1:
fdeposit = depositBalance (deposit);
cout << "After your deposit your current balance is $" << fdeposit << endl;
continue;
case 2:
fwithdraw = withdrawalBalance (withdrawal);
cout << "After your withdrawal your current balance is $" << fwithdraw << endl;
continue;
case 3:
cout << "Your balance is $" << balance <<endl;
continue;
case 4:
cout << "Good-bye!" << endl;
exit (0);
default:
cout << "This is not an option. Please try again!" << endl;
break;
}
} while (selection !=4);
// For loop for transaction accumulator
for (int count = 1; count == (selection == 1 || selection == 2); count++)
{
showStatic ();
}
//Ending messages
cout << "You have completed " << showStatic () << " transactions. ";
cout << "Your beginning balanace is $" << balance << endl;
cout << "Your ending balance is $ " << endl;
system ("pause");
}
void displayMenu ()
{
cout << "Account Menu" << endl;
cout << "-------------------" << endl;
cout << "1. Deposit" << endl;
cout << "2. Withdrawal" << endl;
cout << "3. Check Balance"<< endl;
cout << "4. Exit" << endl;
}
double depositBalance (double num)
{
cout << "How much do you want to deposit? ";
cin >> deposit;
return balance + deposit;
}
double withdrawalBalance (double num)
{
cout << "How much do you want to withdraw? ";
cin >> withdrawal;
return balance - withdrawal;
}
void showStatic ()
{
static int statNum;
cout << "You have completed " << statNum << " transactions." << endl;
statNum++;
}