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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:42:56+00:00 2026-05-30T17:42:56+00:00

How do I pass first_number and second_number to the +add_function ? I am currently

  • 0

How do I pass first_number and second_number to the +add_function?
I am currently getting math undeclared.

Additionally, I have placed the pound include math_class in the -addButtonClicked: IBAction.

Also, I realize that I can simply add the two numbers in the IBAction, but for learning purposes I would like to pass them to my math_class.

-(IBAction)addButtonClicked    
{
    double total;
    double first_number = [firstNumberField.text doubleValue];
    double second_number = [secondNumberField.text doubleValue];

    total = [math_class.add_function number_one:first_number number_two:second_number]; 
    answerField.text =  [NSString stringWithFormat:@"%.2f", total];

    [answerField setHidden:NO];
}

@interface math_class : NSObject

+ (double) add_function: (double) number_one: (double) number_two;

@end

@implementation math_class

+(double) add_function: (double) number_one: (double) number_two
{
    double total;
    total = number_one + number_two;
    return total;
}

@end
  • 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-05-30T17:42:57+00:00Added an answer on May 30, 2026 at 5:42 pm

    There are several problems with the code you posted.

    First of all, the convention in Cocoa Touch is that class names use camel-case and start with a capital letter: MathClass, not math_class. Method names use camel-case and each keyword starts with a lower-case letter. If you stick to the naming convention, it will be easier for other people to understand your code, so it will be easier for you to get help when you have a problem.

    Now, in your math_class class, you have declared a method like this:

    + (double) add_function: (double) number_one: (double) number_two;
    

    But you’ve put in spaces and left out spaces in an unusual way. The usual way to write it, keeping exactly the same method name, looks like this:

    + (double)add_function:(double)number_one :(double)number_two;
    

    The name of this method is add_function::, not add_function number_one:number_two: (which is what you used to try to call it).

    This method name has two keywords. The first keyword is add_function: and takes a double argument named number_one. The second keyword is just : and takes a double argument named number_two.

    You could call this method like this:

    total = [math_class add_function:first_number :second_number]; 
    

    However, using a method name with a keyword of just : is almost always very bad style.

    There are lots of ways to write your class in good style. Here’s one way:

    @interface MathClass : NSObject
    
    + (double)sumWithNumber:(double)firstNumber number:(double)secondNumber;
    
    @end
    
    @implementation MathClass
    
    + (double)sumWithNumber:(double)firstNumber number:(double)secondNumber {
        return firstNumber + secondNumber;
    }
    
    @end
    

    When a method is used primarily for its return value, and not for side effects, we name it after the thing it returns. So I called it sumWithNumber:number: because it returns a sum.

    The method name has two keywords. The first keyword is sumWithNumber: and takes a double argument named firstNumber. The second keyword is number: and takes a double argument named secondNumber. You can call it like this:

    total = [MathClass sumWithNumber:first_number number:second_number];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How would one pass a C# object via com? For example, say I have
I am currently using a number of query string parameters to pass some data
Currently, I have 2 queries: SELECT dateadd(month, x.MonthOffset,0) as [Month], SUM(x.itemcount) as [Total] FROM
I want to implement a two-pass cache system: The first pass generates a PHP
I'm trying to pass a null value for the first parameter in the code
I know you can pass arguments through the RunWorkerAsync function call when you first
Short: how does modelbinding pass objects from view to controller? Long: First, based on
I pass in the following XML to XMLin : <root foo=bar foo2=bar2> <pizzas> <pizza>Pepperoni</pizza>
Goal Pass images generated by one process efficiently and at very high speed to
How do you pass $_POST values to a page using cURL ?

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.