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 8672049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:06:17+00:00 2026-06-12T19:06:17+00:00

Alright. My app has a text field and next to it are two buttons

  • 0

Alright. My app has a text field and next to it are two buttons (Plus button and Equals button). When you press the “Plus” button, it takes the text inside of the textField and adds a “+” to it. Code below:

- (IBAction)plusButtonPressed:(id)sender {
    NSString *plusString = @"+";
    NSString *inputString = carbsField.text;
    NSString *outputString = [NSString stringWithFormat:@"%@%@",inputString,plusString];
    NSLog(@"%@",outputString);
    [carbsField setText:outputString];
}

I will eventually make that more intelligent so that I can’t put two pluses or whatever. Anyway, then I want the equal button to take whatever is in the textField, which should look something like: “23+54+2.2” and get the sum of those values. I believe I know how to take an Integer and make it a String, but I want to verify it:

int value = 56;
NSString *string = @"%d",value;

Well, if anyone can show me how to do this, I would be very appreciative. Thanks.

EDIT
At the moment, I have not tried anything. This is because I do not know where to start. I have an idea of what to do, but I do not know how to execute it. I believe I need to get all characters before a “+” convert them into int and then get the sum of some array of those values.

Edit #2
I now use:

- (IBAction)equalButtonPressed:(id)sender {
    NSString *inputString = carbsField.text;
    NSArray *numbers = [inputString componentsSeparatedByString:@"+"];
    int sum = 0;
    for (NSString *number in numbers) {
        sum += [number intValue];
    }
    NSString *theSum = [NSString stringWithFormat:@"%d",sum];
    NSLog(@"%@",theSum);
}

However, it won’t log anything at all. What did I do wrong?

  • 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-12T19:06:18+00:00Added an answer on June 12, 2026 at 7:06 pm

    It depends on how complex this is going to get. If you’re looking to implement a more complex calculator I recommend looking for an evaluator library that can do this for you.

    However if all you want is to add a bunch of numbers in a list, you could do it like this:

    NSString *input = @"1+2+3.5";
    NSArray *numbers = [input componentsSeparatedByString:@"+"];
    float sum = 0;
    for (NSString *number in numbers) {
       sum += [number floatValue];
    }
    NSLog(@"Result: %f", sum); 
    

    Note that this is very inflexible code and does only what you described.

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

Sidebar

Related Questions

Alright, here goes. I'm making a very basic app, and I want the user
I have a resources web app, which only has static content, such as images,
Alright I am making an Android app, and using the CAPTURE_PIC_REQUEST to take a
Alright so I'm working on a project where I want the app to check
Alright, so here's the dealio: I'm working on a Ruby app that'll take data
Alright, here we go. I have a cocos2d app, and there are targets that
Okay, this is pretty weird. I made an app that listens for changes inside
I am deploying a django-nonrel app on Google App Engine. The app deploys alright
Alright, so I'm building a web app that provides music information (i.e. info on
When downloading my app from Market, when I tap on the Open button to

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.