I'm trying to make a compound interest program for an assignment that tells me at what point Bob's compound interest will catch up with Alice's flat, higher interest rate. Right now, when I enter in their beginning amount, it simply returns that value, prints INF twice, and then some really high number for the year, in the 20,000s, depending on what my starting amount was. Can anyone help me find out why it's doing this?
Alice will always have a higher percentage rate than Bob. Bob's interest rate is defined on line 10. Take a look at your while condition on line 52. We already know Bob will always the lower amount of money, so this is always going to perform whatever is in the inside the do brackets, which they will always be getting more and more money, leading to infinity.
As your code has defined, Alice will ALWAYS have more money than Bob until both reach infinity.
You are compounding the interest for both Alice and Bob - yet you said in the statement of your problem that Alice had a "flat" interest rate (presumably simple, rather than compound interest). Alice's interest should be based on the principal (the initial amount invested), not the accumulated amount with interest added every year.
Incidentally, apropos of nothing, since alice_money is a double, what interest rate applies if it is input as 99.5? or 199.5 etc.?
fiji885 was correct, it was that I forgot to set up Alice's interest as non-compounding. I have the correct setup now, and it provides accurate outputs. The only problem left is that I'm supposed to set it up that any value less than 1 is set to 1. I added an if statement before the if/else if section stating that:
if (alice_deposit < 1)
{
alice_deposit = 1)
}
But when I enter -1 into the program for the initial deposit (as per the instructor's request), it doesn't continue the program. It simply stops there.