We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,453 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

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;
    }
1
Contributor
1
Reply
37 Minutes
Discussion Span
1 Year Ago
Last Updated
2
Views
Question
Answered
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

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.5581 seconds using 2.65MB