aspose file tools*
The moose likes Beginning Java and the fly likes Not Receiving Expected Output Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Not Receiving Expected Output" Watch "Not Receiving Expected Output" New topic
Author

Not Receiving Expected Output

Sam Sething
Greenhorn

Joined: Oct 27, 2012
Posts: 1
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

Joined: Jan 28, 2003
Posts: 4181
    
  21

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.


Steve
Kemal Sokolovic
Bartender

Joined: Jun 19, 2010
Posts: 825
    
    5

And that code would look better to me if you've used do-while loop.


The quieter you are, the more you are able to hear.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Not Receiving Expected Output