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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:14:31+00:00 2026-05-28T05:14:31+00:00

New to objective-c and I just can’t find the answer to this question anywhere.

  • 0

New to objective-c and I just can’t find the answer to this question anywhere. I’m running a IBAction for a calculation but I need the input from a label to actually equal something else in the equation.

For example:

-(IBAction)calculate; {
  float a = 1.05 if ([label1.text] == 1in);
        a = 2.07 if ([label1.text] == 2in);
        a = 3.07 if ([label1.text] == 3in);
  float b = a*([textField1.text floatValue]);
        label2.text = [[NSString alloc] initWithFormat:@"%2.f", b];
  }

I know I’m not even close to getting it right but I hope you get the idea as to what I’m looking for.

Thank you!

  • 1 1 Answer
  • 1 View
  • 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-28T05:14:32+00:00Added an answer on May 28, 2026 at 5:14 am
    - (void)calculate {
      float a;
      if ([self.inputField.text isEqualToString:@"1in"])      a = 1.05f;
      else if ([self.inputField.text isEqualToString:@"2in"]) a = 2.07f;
      else if ([self.inputField.text isEqualToString:@"3in"]) a = 3.07f;
      else a = 0.0f;
    
      if (a) {
        float b = a * ([self.inputField.text floatValue]);
        self.inputField.text = [[NSString alloc] initWithFormat:@"%.2f", b];
      }
      else self.inputField.text = @"Invalid";
    }
    
    - (void)viewDidLoad
    {
      //...
    
      self.inputField = [[UITextField alloc] initWithFrame:CGRectMake(10.0f, 20.0f, 300.0f, 30.0f)];
      [self.inputField setBackgroundColor:[UIColor grayColor]];
      [self.view addSubview:self.inputField];
    
      UIButton * doneButton = [[UIButton alloc] initWithFrame:CGRectMake(10.0f, 55.0f, 300.0f, 30.0f)];
      [doneButton setBackgroundColor:[UIColor blackColor]];
      [doneButton setTitle:@"Done" forState:UIControlStateNormal];
      [doneButton addTarget:self action:@selector(calculate) forControlEvents:UIControlEventTouchUpInside];
      [self.view addSubview:doneButton];
      [doneButton release];
    }
    

    Note: I replaced the output format %2.f to %.2f, cause I guess you may need this format. E.g:

    Input > 1in
    Output< 1.05
    
    Input > 2in
    Output< 4.14
    
    Input > 3in
    Output< 9.21
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am fairly new to Objective-C, but haven't been able to find the answer
I'm new to prolog and I just can't figure this out. I'm trying to
I've searched but can't find an answer. There is a website with a contact
First, I am super-new to Objective-C/iOS development and, in fact, this question is for
I'm new to Objective-C and development on Apple's platforms, but hopefully I can frame
Still new to Objective C, and I'm having some trouble that I just can't
I'm fairly new to objective c but I'm using this code NSURL *url =
I'm new to objective C and I just wanted to get a general clarification
another Objective-C one for you, probably pretty obvious but I have been at this
I'm a little new to objective-C but have run across a problem that I

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.