Hi,
I'm writing a small program that takes an input file such as this:
then processes the info, adding or subtracting to the balance of the checking or savings account as needed.
Ideally, the output should be similar to this:
My program will consist of 3 additional boolean functions (titled: deposit, withdrawl, transfer) to handle the processing of this information (seems silly to me why these are boolean; checking to see if it will be succesful should happen before the function is called, IMO).
I'm currently just testing the deposit function on the checking account, seeing if I get the correct total deposit balance at the end, and prints "Success!" for each succesful run.
So far the code I've got is giving me an incorrect answer. I've stared at this for a very long time, and it usually takes a fresh look to spot the problem, so if you can, I'd appreciate any help. I should be getting around 200 as the answer, but it shows me "0." For some reason, the checking_balance is not being changed, even though I used 'float &balance' in my function :/
Here is my code so far (please ignore the 'using namespace std;'...bugs me too, but the prof makes us use it):
I'm writing a small program that takes an input file such as this:
Code:
Checking Deposit 50.00
Savings Deposit 100.00
Savings Withdrawal 21.50
Checking Transfer 42.68
Checking Deposit 14.95
Checking Withdrawal 25.00
Savings Deposit 1.25
Checking Deposit 25.00
then processes the info, adding or subtracting to the balance of the checking or savings account as needed.
Ideally, the output should be similar to this:
Code:
Welcome to the Bank!
Please enter your name: Mark
Transaction Amount Savings Checking
-------------------- ---------- -------- -----------
Checking Deposit 50.00 0.00 50.00
Savings Deposit 100.00 100.00 50.00
Savings Withdrawal 21.50 78.50 50.00
Checking Transfer 42.68 121.18 7.32
Checking Deposit 14.95 121.18 22.27
Checking Withdrawal 25.00 *Insufficient Funds*
Savings Deposit 1.25 122.43 22.27
Checking Deposit 25.00 122.43 47.27
Thanks for visiting the bank Mark
My program will consist of 3 additional boolean functions (titled: deposit, withdrawl, transfer) to handle the processing of this information (seems silly to me why these are boolean; checking to see if it will be succesful should happen before the function is called, IMO).
I'm currently just testing the deposit function on the checking account, seeing if I get the correct total deposit balance at the end, and prints "Success!" for each succesful run.
So far the code I've got is giving me an incorrect answer. I've stared at this for a very long time, and it usually takes a fresh look to spot the problem, so if you can, I'd appreciate any help. I should be getting around 200 as the answer, but it shows me "0." For some reason, the checking_balance is not being changed, even though I used 'float &balance' in my function :/
Here is my code so far (please ignore the 'using namespace std;'...bugs me too, but the prof makes us use it):
Code:
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
bool deposit(float,float); // processes deposits
bool withdrawal(float,float); // processes withdrawals
bool transfer(float,float,float); // processes transfers
int main()
{ string user,filename;
fstream transaction_file;
float checking_balance,savings_balance;
float amount;
string account, action;
// set both balances to $0.00
checking_balance = 0.00;
savings_balance = 0.00;
// begin, prompt for name, and open the corresponding file
cout << "Welcome to the Bank!\n\n"
<< "Please enter your name: ";
cin >> user;
filename = "/Users/Josh/Desktop/"+user+".txt";
transaction_file.open(filename.data(),ios::in);
while(!transaction_file.eof() && !transaction_file.fail())
{ transaction_file >> account,action,amount;
if(account == "Checking" && action == "Deposit")
if(deposit(checking_balance,amount))
cout << "Success!" << endl;
}
// close the file
transaction_file.close();
cout << "Total amount of deposits = " << checking_balance << endl;
return 0;
}
bool deposit(float &balance,float amount)
{ if(amount >= 1)
{ balance += amount;
return (true);
}
else
return (false);
}