Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8472927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:12:35+00:00 2026-06-10T17:12:35+00:00

I am a newbie in programming, currently across some difficulties in my first school

  • 0

I am a newbie in programming, currently across some difficulties in my first school work. Can anyone tell me am I doing on the right track? The aim of this code is to do add two numbers around 70 digits which cannot be done using the int or long int type in Objective-C. The following code keeps getting warning: incompatible pointer types returning ‘NSString *__strong’ from a result type ‘MPInteger *’ Help please, I have already been figuring out for ages and got nothing.

MPInteger.h

#import <Foundation/Foundation.h>

@interface MPInteger : NSObject
@property (copy, nonatomic) NSString * description;

-(id) initWithString: (NSString *) x;
-(NSString *) description;
-(MPInteger *) add: (MPInteger *) x;

MPInteger.m

#import "MPInteger.h"

@implementation MPInteger

@synthesize description;

-(id) initWithString: (NSString *) x {
    self = [super init];
    if (self) {
        description = [NSString stringWithString: x];
    }
    return self;
}

-(NSString *) description {
    return description;
}

-(MPInteger *) add: (MPInteger *) x
{
    int carry = 0;
    int index = 0;
    int index2 = 0;
    int i;
    int num1;
    int num2;
    int result;


    index = [description length];
    index2 = [x.description length];


    while (index2 < index) {
        x.description = [x.description stringByPaddingToLength:index withString:@"0" startingAtIndex:0];
    }

    for (i = index; i <= index || carry != 0; i--) {
        num1 = [description characterAtIndex:index];
        num2 = [x.description characterAtIndex:index];
        result = num1 + num2 + carry;
        // if the sum is less than 10
        if (result < 10) {
            NSString *intString = [NSString stringWithFormat:@"%i", result];
            [description replaceValueAtIndex:index inPropertyWithKey:intString withValue:@"%@"];
            // replace the description index value with the sum
        } else { //otherwise
            NSString *intString = [NSString stringWithFormat:@"%i", result];
            //getting the index'1' is the value replace the description index value
            [description replaceValueAtIndex:index inPropertyWithKey:[intString substringFromIndex:1] withValue:@"%@"];
            carry = 1;
        }
        index--; // decrement index
    }
    return description;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T17:12:37+00:00Added an answer on June 10, 2026 at 5:12 pm

    You declare your method to return an MPInteger:

    - (MPInteger *)add:(MPInteger *)other;
    

    but you finally return description, which is an NSString instance.

    You perhaps meant to make an MPInteger instance out of the string before returning:

    return [[MPInteger alloc] initWithString:description];
    

    (add autorelease if you don’t use ARC).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am complete newbie for programming and this is my first real program I
I'm a newbie in php programming and i can't make it finding where is
Programming newbie here, about a month in with Ruby. I'm currently playing around with
I'm currently solving a programming problem to enhance my skills (I'm still a newbie)
I'm a programming newbie, and I can't figure out how to store a function
I am a complete Android programming newbie. I have completed some tutorial examples like
I am a newbie to programming and need some help with the basics. I
Newbie here programming my first app (having made several tutorial apps). I am using
I am a newbie to programming. I have a very basic question that Can
I'm a newbie to programming and need some help with the set of fixers

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.