Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Error Help
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Monophobia




PostPosted: Wed Apr 10, 2013 10:09 pm   Post subject: Error Help

I keep getting a return error. I tried placing a return command in various shapes and places, but continue to get errors. Either it gives me an error in which the thing can't get to the problem or it gives me several more errors. Here is my coding thus far.
code:

{
public static double futureInvestmentValue(double investmentAmount, double monthlyInterestRate, int years)
{
Scanner in = new Scanner(System.in);
double futureInvestmentValue;
System.out.print("ENTER INVESTMENT AMOUNT HERE: ");
investmentAmount =in.nextDouble();
System.out.print("ENTER MONTHLY INTEREST RATE HERE: ");
monthlyInterestRate = in.nextDouble();
for (years = 0; years > 0 ; ++years)
{
int exp = years * 12;
futureInvestmentValue = investmentAmount * (1 + Math.pow(monthlyInterestRate, exp));
System.out.println("Year " + years + " Investment " + futureInvestmentValue);

}
}
Sponsor
Sponsor
Sponsor
sponsor
Panphobia




PostPosted: Wed Apr 10, 2013 10:22 pm   Post subject: RE:Error Help

are you trying to return futureInvestmentValue? if so I think you might need to initialize it to some value first.
Monophobia




PostPosted: Wed Apr 10, 2013 10:42 pm   Post subject: Re: Error Help

I initialized it and it did not work.
ishidon




PostPosted: Wed Apr 10, 2013 10:43 pm   Post subject: Re: Error Help

So you have many errors in this code:
First of all, you have three parameters for your function, investmentAmount, monthlyInterestRate, and years.
However all of your parameters are being reassigned values inside the method so therefore taking them as paramaters does no good for you.

Next in your for loop you must initialize years in order for the for loop to work and also your for loop will never be entered because the initial value of years is 0 and your loop will only execute when years is > 0.

Also as Panphobia said you must initialize futureInvestmentValue because in the current state your code is in, the for loop is never being entered therefore futureInvestmentValue is never being initialized.

Also because your function has:
Java:

public static double futureInvestmentValue(double investmentAmount, double monthlyInterestRate, int years)

This means you MUST return a double value and I believe you are trying to return futureInvestmentValue therefore you can just add
Java:

return futureInvestmentValue;

at the end of your function.

Hopefully this helps you a bit.
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: