Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
February 6th, 2013, 07:52 PM
 Councillor
Registered User

Join Date: Feb 2013
Posts: 1
Time spent in forums: 11 m 53 sec
Reputation Power: 0
Homework - 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;

//Calculations
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
February 6th, 2013, 08:01 PM
 MrFujin
Lord of the Dance

Join Date: Oct 2003
Posts: 3,370
Time spent in forums: 2 Months 2 Weeks 5 Days 2 h 30 m 27 sec
Reputation Power: 1828
You are using modulo instead of division.
6%100 give the result: 6
6/100 give the result: 0.06

 Viewing: Dev Shed Forums > Programming Languages > Java Help > Homework - Simple Interest