Help with simple program
Writing a small program that requires me to convert strings to doubles and then back to strings. Right now, the code compiles but the answer is wrong, even though I am using an algorithm that I know is right in C++. Can someone tell me what I'm doing wrong? The answer that comes out always very large and random.
else{
//Converting Strings to Double INT's
double myMonths = [monthsString doubleValue];
double myBalance = [balanceString doubleValue];
double myInterest = [interestString doubleValue];
//Payment Algorithm
myInterest = (myInterest/100)/12;
double AlmostDone = (myInterest * pow(1 + myInterest, myMonths)) * (myBalance/(pow(1 + myInterest, myMonths) -1));
//Converting a double INT back to a String
NSString *FinalPayment = [NSString stringWithFormat:@"%d", AlmostDone];
//Print to Screen
NSString *paymentScreen = [[NSString alloc] initWithFormat:@"In order to pay your debt in %@ months, you need to pay an average of %@ per month.", monthsString, FinalPayment];
self.label.text = paymentScreen;
}
37 Minutes
Discussion Span
Related Article: Objective-C strange result
is a Objective-C discussion thread by Nfurman that has 1 reply, was last updated 1 year ago and has been tagged with the keywords: cocoa, objective-c.
Navlag
Light Poster
34 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
Nevermind, all you have to is replace %d with %lf.
Navlag
Light Poster
34 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
Question Self-Answered as of 1 Year Ago