Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

# Thread: Writing a loop to determine total savings

1. ## Writing a loop to determine total savings

Hello,

My girlfriend asked me to write a loop to determine the total amount she will save if she starts by putting in \$75 and puts in 1 more dollar every week (75, 76, 77, ... 127).

Right now, I'm stuck at trying to get the for loop to add the extra dollar every week.

Here is what I have so far

Code:
```int save = 75;

for(int i = 1; i<=54; i++){
int deposit = save+i;

int sum = save + deposit;

System.out.println("week " + i + ". Please deposit: " + deposit + " dollars");
System.out.println("You have " + sum + " dollars in the bank");

}```

• I'm not sure if you're running total is referring to the summed saving or to the amount to deposit. Given the result of deposit, I'd suspect that's to be deposit. You'd need to move the sum before the loop and initialize it to save, then add deposit to it within the loop. Simple as that.

• ## Users who have thanked Fou-Lu for this post:

Daren_Z (09-13-2013)

• Funny, this is the sort of question a teacher would ask, not a girlfriend....

• Yeah, she's trying a new way to save, so since I'm alright at math she asked me how much she would save. And I thought it would make some good practice since I haven't touched java in almost a year.

Thanks Fou-lu, I'll try making that change to the code and see how it turns out.

• Originally Posted by Roelf
Funny, this is the sort of question a teacher would ask, not a girlfriend....
Or his gf is his teacher. lol

•