Ok, i'm having real issues with functions, can anyone help me or make suggestions as to how i change this to a function?
Code:
#include <iomanip>
#include <iostream>
#include <fstream>
#include <string>
float deposit(float x);
float withdrawal(float y);
float transfer(float z);
bool funds;
using namespace std;
void main()
{ string filename, account, transaction;
fstream file;
float checking, savings, amount;
cout << "Welcome to the Bank!" << endl << endl;
cout << "Please Enter your name: ";
cin >> filename;
file.open(filename.data(),ios::in);
checking=0;
amount=0;
savings=0;
cout << fixed << setprecision(2) << endl << endl;
cout << left << setw(21) << "Transaction " << left << setw(8) << "Amount " << left << setw(9) << "Savings " << left << setw(9) << "Checking " << endl;
cout << "-------------------- " << "------- " << "-------- " << "--------" << endl;
while(!file.eof())
{
file >> account;
file >> transaction;
file >> amount;
cout << account << " " << left << setw(12) << transaction << " ";
//CHECKING AREA
if(account=="checking")
{
if(transaction=="deposit")
{
checking = amount + checking;
cout << right << setw(6) << amount;
cout << right << setw(9) << savings;
cout << " " << right << setw(8) << checking << endl;
}
else if(transaction=="withdrawal")
{
if(amount<checking)
{
funds=true;
}
else
{
funds=false;
}
if(funds)
{
checking = amount - checking;
cout << right << setw(6) << amount;
cout << right << setw(8) << savings;
cout << " " << right << setw(8) << checking << endl;
}
else if(!funds)
{
cout << right << setw(6) << amount << " ";
cout << right << setw(10) << "Insufficient Funds" << endl;
}
}
else if(transaction=="transfer")
{
checking = checking - amount;
savings = amount + savings;
cout << right << setw(6) << amount;
cout << right << setw(9) << savings;
cout << " " << right << setw(8) << checking << endl;
}
}
//SAVINGS AREA
else if(account=="savings")
{
if(transaction=="deposit")
{
savings = amount + savings;
cout << right << setw(7) << amount;
cout << right << setw(9) << savings;
cout << " " << right << setw(8) << checking << endl;
}
else if(transaction=="withdrawal")
{
savings = savings - amount;
cout << right << setw(7) << amount;
cout << right << setw(9) << savings;
cout << " " << right << setw(8) << checking << endl;
}
}
};
cout << endl;
}
I know that true/false thing is redundant, but our teacher wanted us to use a bool to determine if theres enough funds according to true and falses. There are supposed to be three functions, a deposit, withdrawal, and transfer. I believe the trasnfer needs two paramaters.
I tried cutting out a deposit if statement and try to put that in a function, but it wouldnt work.
any help much apreciated.