Java Help
So I have to make this investment calculator which is posted down below me. After I compile and run it. The file seems t
rk perfectly fine except for one error. If I told it 100 for Initial Investment and then 500 for Investment goal. It says it would take 499 years. What did I do wrong?
rk perfectly fine except for one error. If I told it 100 for Initial Investment and then 500 for Investment goal. It says it would take 499 years. What did I do wrong?/**
* @(#)Investment 2.java
*
*
* @author
* @version 1.00 2011/1/16
*/
import java.util.*;
public class Investment2 {
public static void main(String[] args) {
double principal = 0;
double interest = 0;
double rate = 0.10;
int years = 0;
double goal = 0;
double total = 0;
int userinput = -1;
Scanner myScanner = new Scanner(System.in);
// Welcome message
System.out.println("Welcome to the Investment Calculator Beta");
// Enter initial amount
System.out.println ("Enter initial investment amount. If you want to exit enter 0.");
int input1 = myScanner.nextInt();
principal = input1;
// Decision for exit
if (input1 == 0){
System.exit(0);
}
// Enter goal amount
System.out.println ("Enter your goal investment amount: ");
int input2 = myScanner.nextInt ();
goal = input2;
System.out.println ("The fixed interest rate is 10%"); //Change if you have different rate
// Loop to get total years
total= principal;
total= (interest+1)*total;
for (total = 0; total < goal; total++){
System.out.println("To reach your $" + goal + "0 goal it will take " + years + " years.");
years++;
// Continue play
if (total == goal){
System.out.println("Would you like to enter another amount?");
int input3 = myScanner.nextInt ();
} while (userinput == 1);
}
}
}