How would I go about calculating a compound interest rate, so far I have:
double principal = [[principalLabel text] doubleValue];
NSLog(@"Principal: %lf",principal);
double years = [[yearsLabel text] doubleValue];
NSLog(@"Years: %lf",years);
double months = [[monthsLabel text] doubleValue] / 12;
NSLog(@"Months: %lf",months);
double days = ([[daysLabel text] doubleValue] / 365) / 10;
NSLog(@"Days :%lf",days);
double rate = ([[rateLabel text] doubleValue] / 100);
NSLog(@"Rate: %lf",rate);
double time = years + days + months;
NSLog(@"Time: %lf",time);
double total = pow(principal * (1 - rate), time);
NSLog(@"Total: %lf",total);
double interest = pow(principal * (1 - rate), time) - principal;
NSLog(@"Interest: %lf",interest);
NSString *interestString = [[NSString alloc] initWithFormat:@"%lf",interest];
NSString *totalString = [[NSString alloc] initWithFormat:@"%lf",total];
[interestLabel setText:interestString];
[totalLabel setText:totalString];
So as you can see I have 5 UITextFields for the: principal, rate, years, months, days. At the moment I keep getting some answer that is no where near the actual answer I am after even though my math seems correct I have reviewed my code thoroughly and found no solution.
My desired result is: E.g.
M = P * (1+R)^Y
M = 1000 * (1+0.10)^2
M = 1210
If you place the output from the NSLog messages in your question also, it will be even more helpful to answer your question. Right now an obvious mistake is mentioned below:
In this line of code
you have 1 – rate, while you need to have