• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Not Receiving Expected Output

 
Sam Sething
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a project where I am suppose to write a program that prompts the user for an initial investment amount and a goal investment amount and calculate how many years it will take to grow from the initial amount to the goal amount with a fixed interest rate (ie: 5 %). (use the WHILE loop). Print out the results from each year. For example, if you chose to invest $1,000 for 5 years:
Year 1 1005
Year 2 1011
Etc:

I was able to to input initial investment amount and goal investment amount and calculate how many years at 5% interest it would take to get it but the code does not output what each year yields. Here is my code.


What am I doing incorrectly?

Respectfully.
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sam Sething wrote:...Print out the results from each year. For example, if you chose to invest $1,000 for 5 years:
Year 1 1005
Year 2 1011
Etc:
...What am I doing incorrectly?


Welcome to the ranch!

Well, the main thing you are doing is never printing those values out. You have a for loop, and in that for loop you print out the goal, and the current year. This probably isn't what you want to do. What you probably want to do is print that out just once before the loop. Then in the for loop print out the text you want to display:
"Year" + year + " $" + total amount this year.
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And that code would look better to me if you've used do-while loop.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic