First let me start by saying that I hope I wrapped my code properly.
Next, my instructor sent us some code using a class and instructed us to add to it and make it so that we can display a checking account balance from a simple three line text file, then add and subtract from that balance.
I will get the adding and subtracting, but what is giving me problems is how do I pass a value from my "deposit" variable up to my money::addchecking function? I have watched a half dozen videos, and thought I followed them correctly but I am doing something wrong.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int checkingfunction();
class money
{
double checking;
double savings;
double cash;
public:
double deposit (0);
money();
~money();
double showcash();
double showchecking();
double addchecking();
double subtractchecking();
};
money::money()
{
char readline[100];
int pennies;
ifstream inputFile;
inputFile.open("balance.txt");
if (inputFile.good())
{
inputFile >> readline;
pennies = atoi(readline);
checking = pennies/100 + (pennies%100)*.01;
inputFile >> readline;
pennies = atoi(readline);
savings = pennies/100 + (pennies%100)*.01;
inputFile >> readline;
pennies = atoi(readline);
cash = pennies/100 + (pennies%100)*.01;
inputFile.close();
}else cout << "file not found" << endl;
}
money::~money()
{
int pennies;
char writeline[100];
ofstream outputFile;
outputFile.open("balance.txt");
pennies = checking*100;
itoa(pennies, writeline, 10);
outputFile << pennies << endl;
pennies = savings*100;
itoa(pennies, writeline, 10);
outputFile << pennies << endl;
pennies = cash*100;
itoa(pennies, writeline, 10);
outputFile << pennies << endl;
outputFile.close();
}
double money::showcash()
{
return cash;
}
double money::showchecking ()
{
return checking;
}
double money::addchecking()
{
checking=checking+deposit;
return checking;
}
int main (int argc, char* argv[])
{
money roger_money;
cout << "cash on hand is " << roger_money.showcash() << endl;
money checkdeposit;
cout << "checking is " <<checkdeposit.showchecking() << endl;
double deposit;
cout << "How much would you like to deposit to checking?"<< endl; //Ask for deposit amount
cin >> deposit;
cout << "deposit amount is $"<< deposit<< endl; //Show amount being Deposited
checkdeposit.addchecking(deposit)
//how do I pass "deposit" to the function double money::addchecking()?
system("pause");
return 0;
}