What's wrong with my code

The question is.
When Robin's new baby was born, she opened a savings account with $1,000.00 On each birthday, starting with the first, the bank added an additional 5% of the balance and Robin added another $500.00 to the account. Develop a program that will determine how much money was in the account on the child's 18th birthday.

int main(int argc, char *argv[]) {

int i = 1000;
int birthday;

for (birthday; i < 18000; birthday++)
{
birthday = birthday + birthday/0.5;
}
cout << birthday << endl;



system("PAUSE");
return EXIT_SUCCESS;
}
So many problems it's hard to determine where to start.

So the bank starting amount is 1000, that should be named bank, not i, since i is not really descriptive. Of course this is personal preference, not required by programming but it's what I used in the examples below.

Then your for statement should look like

for (int birthday=0; birthday < 18; birthday++)

Now your next line should be
bank = bank + 500 + (bank*.05);

Finally you want to cout the bank total, not the number of birthdays.
Last edited on
[Error] lvalue required as left operand of assignment

bank = bank + 500 + (bank*.05); ??? whyy
[Error] lvalue required as left operand of assignment

We can't say without more context.

Following @SamuelAdams' suggestions, you should end up with something like this:
1
2
3
4
5
6
7
8
9
# include <iostream>

int main() {
  double balance = 1000.00; 
  for (int year = 0; year < 18; ++year)
    balance = balance + 500 + (balance * .05);

  std::cout << balance << '\n';
}

Live demo:
http://coliru.stacked-crooked.com/a/911798146cc12444
Last edited on
Topic archived. No new replies allowed.