Compound Interest Calculator with a loop?

Working on a homework assignment and getting stuck. Here are the instructions:

Use App Inventor to create an app with three textboxes (with labels), a button and a label.

  • The first textbox is for the amount of the investment, like 1000. It should be NumbersOnly.
  • The second textbox is for the APR (the annual percentage rate), entered as, for example, .055 for 5.5%. It should be NumbersOnly.
  • The third textbox is for the number of years to invest, NumbersOnly.
  • The label below the button is where the final value will go.
  • When the button is clicked,
    • initialize a variable apr to the apr text.
    • initialize a variable value to the investment text.
    • loop for the number of years. In the do part of the loop, set value to value(apr+1)*.
    • AFTER the loop, set the text of the last label to value

We have to use a loop to calculate it and we can't use the actual formula for calculating compound interest without a loop. Here's the blocks that I have so far:

What am I missing or what did I do wrong?

This might help you:

I tried this one before I posted my question and it didn't help with this particular assignment. The example in that post shows with a compound interest formula whereas, my instructor does not want us to use that formula. So I'm trying to figure out a way to do it without it and with only the one she has listed. I believe she also wants us to use a while loop whereas that one has an if/then. Thanks for trying to help!

It looks like you are forgetting to decrement the years each time through the loop, so you basically get stuck in an infinite loop because years will always be >= 1.

2 Likes

You might also want to look in the control blocks for the
for each number from 1 to years by 1 block

I figured I needed a way to counteract the infinite loop. Did my decrement and now it works! Thanks so much!

Or just this:

1 Like

Or with your textboxes:

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.