Thread: Simple Interest

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

    Join Date
    Feb 2013
    Rep Power

    Simple Interest

    Having to write a code for finding simple interest in my fundamentals class and when I run the program I'm not getting the right output.

    The interest is 450000.0 <-------problem
    The amount is 5000.0
    The total years is 15
    The rate is 6

    The interest should be 4500.0 but has a few to many 0's on there. Main problem is my professor gave guidelines, such as the interest and amount must be decimals and then years and rate must be integers, so I can't just change the rate to double rate =0.06;

    //Define variables
    double interest = 0;
    double amount = 5000;
    int years = 15;
    int rate = 6;

    interest = amount * (rate%100) * years;

    This is the code for the most part just left out the output, there are no errors when I run it, I just get the interest equaling 450000.0 instead of 4500.0

    Anyone have any ideas as to what I might be doing wrong here?
  2. #2
  3. Lord of the Dance
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Oct 2003
    Rep Power
    You are using modulo instead of division.
    6%100 give the result: 6
    6/100 give the result: 0.06

IMN logo majestic logo threadwatch logo seochat tools logo