Probably the simplest question you'll answer today.

so I have been fighting with this thing all week, and I'm finally closing in on finishing. However, I can not for the life of me get this function to display correctly.
Everything else about my program works great, except this one cout function.
this is a bank account simulator and it is supposed to be part of a savings account.
Its supposed to show like this:
1
2
It has been (x) days since your last transaction.
Interest Earned:$(y) Current Balance:$(z)


it shows everything in the cout function except the first two, and I can't figure out what is wrong.

I'm going to just drop the function followed by how each chunk is defined.

every function works correctly behind the scenes. the only issue i'm assuming is how i'm returning the private variables.
the only part of getInterestEarned that displays correctly is getAccountBalance

1
2
3
4
5
6
7
8
9
SavingsAccount account2;

account2.getInterestEarned(); account2.depositMoney();
		cout << "It has been "; account2.showNumberofDays(); 
		cout << " days since your last transaction." << endl;
		cout << showpoint << fixed << setprecision(2);
		cout << "Interest Earned: $"; account2.getInterestEarned();
		cout << showpoint << fixed << setprecision(2);
		cout << "Current balance: $" << account2.getAccountBalance() << endl;

1
2
3
4
5
6
7
8
9
10
11
12
13
int	SavingsAccount::showNumberofDays()
	{
	return numberOfDays;	//private variable of SavingsAccount class
	};

double	SavingsAccount::getInterestEarned()
	{
	getNumberOfDays();    //gets a random number 0-8
	interestAdded = ( getAccountBalance() * numberOfDays * ( getInterestRate() / 365) );
	depositAmount = interestAdded; //both public variables
	depositMoney(); //adds deposit amount to accountBalance (private variable)
	return interestAdded;
	};


thoughts?

I have another small issue. I need to count the number of transactions to charge a fee every transaction after the third. What is the best way to store this variable? when i call this function it doesn't increment properly, i can't get it to call out.
1
2
3
4
5
6
7
8
9
10
11
void	CheckingAccount::transactionLimiter()
{
	Counter++;
		if (Counter >= 3)
		{
			cout << "Free transactions exceeded. Transaction fee deducted.";
			cout << endl;
		withdrawAmount = transactionLimitFee;
			withdrawMoney();
		};
};
Last edited on
cout << "It has been "; account2.showNumberofDays();
should be
cout << "It has been " << account2.showNumberofDays();

Line 7 has a similar issue. You aren't doing anything with the value returned from those functions.
I knew it would be something simple. I can't believe I didn't see that.
Thank you so much for your help.

now that that has been sorted, I have a new issue. Something is wrong with the math in there. It returns the interest earned and usually adds double to the new total.
neither number is correct.
example, just ran and got 5 days gave me .02 interest and my balance was 100.10
meanwhile the correct interest added was about .04

I know the deposit function is working correctly. Its simply
accountBalance = accountBalance + depositAmount

EDIT: figured it out, was calling the getInterestEarned function twice, and it already has a deposit function call.
I was depositing it three times per call.
Last edited on
Topic archived. No new replies allowed.