Help with adding something up
Need to add up the total amount PAID, im not sure how though
33 Replies
Well you already have a while loop that keeps running until you reach 0, so in that loop you should keep summing up the monthly payment and interest accrued each month at the same time to a total variable
You even know what the total loan amount is so you could start it at that and then just add the interest each loop
thats the part that confuses me
im not sure how to do it
Think about what you're doing with your
loan
variable inside the while loop, and how it's really not all that differentwhy does it do this when its outside the while loop
Did you declare your total variable inside the while loop?
yes
That's why then
its what im supposed to do, no?
No, if you declare it inside the loop a) it's restricted to that scope, and b) it will reset to 0 on each iteration of the loop so won't actually get your total
You should declare it before the loop, same as you did with loan
so this will work?
Give it a go
definitely removed the error
still confused on the total though
Why?
dont know how to get it 😭
What do you mean "get it"?
the total amount
That's not what I asked
well how to calculate it
i always get some low number, which doesnt quite make sense
What's the code you've added for it?
ive tried
inside the loop
but that didnt work
Well, that should give you a big number, too big a number, because you're adding the remaining loan amount every time
it gave me a number below 10000
like 600 something
Yes sorry I just reread it, so there are two issues, you're adding the loan amount and you're not taking into account the existing total value
For example when you're calculating the loan amount you start with
loan = loan...
Working out this specific line isn't particularly a programming problem, think about how you would do it if you were keeping track of the total you paid each month in a notebook or somethingtotal = total + loan would give me a huge number
I already said adding loan was wrong? Why would you add loan each time?
im slow
If you wanted to include the loan then you would start the total amount at the loan amount once, before the while loop, then just add the interest each time in the loop
OR
You would start total at 0 and add the monthly amount and interest amount inside the loop
OH MY GOD
THANK YOU
THANK YOU SO MUCH
IT WORKS
You're welcome honestly though you had done a lot of similar things already, so in theory you could have figured it out (though don't be afraid to ask for help), so perhaps just try and break things down into smaller chunks/write things down etc to help you figure them out
my brain isnt functioning well today at all
And sometimes just take a break!
Having a break then coming back to it can help
its because of the math exam i had today
my math since then has been
questionable