#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    1
    Rep Power
    0

    Need help to fix the compound interesr program


    i have homework to write the program which can calculate the compund interest for 30 years and print out the interesrt for yearly monthly and daily. i have wrote the program but it giving out the wrong result the result i want is as follow:

    | year | yearly | monthly | daily |
    | 1|$10500.00|$10511.62|$10512.67|
    | 2|$11025.00|$11049.41|$11051.63|
    | 3|$11576.25|$11614.72|$11618.22|
    | 4|$12155.06|$12208.95|$12213.86|
    | 5|$12762.82|$12833.59|$12840.03|
    | 6|$13400.96|$13490.18|$13498.31|
    | 7|$14071.00|$14180.36|$14190.34|
    | 8|$14774.55|$14905.85|$14917.84|
    | 9|$15513.28|$15668.47|$15682.64|
    | 10|$16288.95|$16470.09|$16486.65|
    | 11|$17103.39|$17312.74|$17331.88|
    | 12|$17958.56|$18198.49|$18220.44|
    | 13|$18856.49|$19129.56|$19154.56|
    | 14|$19799.32|$20108.26|$20136.56|
    | 15|$20789.28|$21137.04|$21168.91|
    | 16|$21828.75|$22218.45|$22254.19|
    | 17|$22920.18|$23355.19|$23395.11|
    | 18|$24066.19|$24550.08|$24594.52|
    | 19|$25269.50|$25806.11|$25855.41|
    | 20|$26532.98|$27126.40|$27180.96|
    | 21|$27859.63|$28514.24|$28574.46|
    | 22|$29252.61|$29973.08|$30039.40|
    | 23|$30715.24|$31506.56|$31579.44|
    | 24|$32251.00|$33118.50|$33198.44|
    | 25|$33863.55|$34812.90|$34900.44|
    | 26|$35556.73|$36594.00|$36689.70|
    | 27|$37334.56|$38466.22|$38570.69|
    | 28|$39201.29|$40434.22|$40548.11|
    | 29|$41161.36|$42502.91|$42626.91|
    | 30|$43219.42|$44677.44|$44812.29|

    [code=java]

    <

    my program is as follow:

    import java.util.Scanner;

    public class money {




    public static void main(String[] args) {
    double y_amount=0;
    double m_amount=0;
    double d_amount=0;
    double principal=0;
    double rate=0;
    int n=0;

    Scanner in = new Scanner (System.in);

    System.out.print ("what is the starting balance (in dollars)?: ");
    principal = in.nextDouble();
    System.out.print("what's the yearly interesr rate (in percentage)?: ");
    rate = in.nextDouble();
    System.out.print("For how many year will you be saving?: " );
    n= in.nextInt();

    System.out.println();
    System.out.println();
    System.out.println(" Using:" + "starting balance-" + principal);
    System.out.println("Yearly interest rate-" + rate);
    System.out.println("Years to save-" + n);

    System.out.println("|year | yearly | monthly| daily|");
    for (int year=1; year<=n; year++){
    y_amount = principal * Math.pow(1+ (rate/100.0), year);




    for (int month=1; month<=(n*12); month++){
    m_amount = principal * Math.pow(1+ ((rate/12)/100.0), month);

    }



    for (int day=1; day<=(n*365); day++){
    d_amount = principal * Math.pow(1+ ((rate/365)/100.0), day);

    }

    System.out.format("|%6d|$%.2f|$%.2f|$%.2f|\n", year, y_amount, m_amount, d_amount);
    }









    }
    }
    >
    [/code]


    principal=10000
    rate=5%
    year=30



    my current result is as follow:
    what is the starting balance (in dollars)?: 10000
    what's the yearly interesr rate (in percentage)?: 5
    For how many year will you be saving?: 30


    Using:starting balance-10000.0
    Yearly interest rate-5.0
    Years to save-30
    |year | yearly | monthly| daily|
    | 1|$10500.00|$44677.44|$44812.29|
    | 2|$11025.00|$44677.44|$44812.29|
    | 3|$11576.25|$44677.44|$44812.29|
    | 4|$12155.06|$44677.44|$44812.29|
    | 5|$12762.82|$44677.44|$44812.29|
    | 6|$13400.96|$44677.44|$44812.29|
    | 7|$14071.00|$44677.44|$44812.29|
    | 8|$14774.55|$44677.44|$44812.29|
    | 9|$15513.28|$44677.44|$44812.29|
    | 10|$16288.95|$44677.44|$44812.29|
    | 11|$17103.39|$44677.44|$44812.29|
    | 12|$17958.56|$44677.44|$44812.29|
    | 13|$18856.49|$44677.44|$44812.29|
    | 14|$19799.32|$44677.44|$44812.29|
    | 15|$20789.28|$44677.44|$44812.29|
    | 16|$21828.75|$44677.44|$44812.29|
    | 17|$22920.18|$44677.44|$44812.29|
    | 18|$24066.19|$44677.44|$44812.29|
    | 19|$25269.50|$44677.44|$44812.29|
    | 20|$26532.98|$44677.44|$44812.29|
    | 21|$27859.63|$44677.44|$44812.29|
    | 22|$29252.61|$44677.44|$44812.29|
    | 23|$30715.24|$44677.44|$44812.29|
    | 24|$32251.00|$44677.44|$44812.29|
    | 25|$33863.55|$44677.44|$44812.29|
    | 26|$35556.73|$44677.44|$44812.29|
    | 27|$37334.56|$44677.44|$44812.29|
    | 28|$39201.29|$44677.44|$44812.29|
    | 29|$41161.36|$44677.44|$44812.29|
    | 30|$43219.42|$44677.44|$44812.29|
  2. #2
  3. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,724
    Rep Power
    348
    Please edit your post and wrap your code with code tags:
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.

    Also please post the contents of the console that shows the input and the program's current output.

IMN logo majestic logo threadwatch logo seochat tools logo