1.11M Members

Help with simple program

 
0
 

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;
    }
 
0
 

Nevermind, all you have to is replace %d with %lf.

Question Self-Answered as of 2 Years Ago
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: