February 6th, 2013, 07:52 PM
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;
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?
February 6th, 2013, 08:01 PM
You are using modulo instead of division.
6%100 give the result: 6
6/100 give the result: 0.06