user3587655
user3587655

Reputation: 1

Simple math iOS app?

I'm pretty new to programming, and I just need to be pointed in the right direction with this.

I'm trying to make an iOS app in Xcode (using Objective-c) that takes in the user's input and uses a 3x3 cramer's rule matrix to feed back a coordinate. I've been learning about properties and methods, and I'm just confused as to how I can get the user's input (12 numbers), alter them mathematically, and print out the answer.

So far, I've been able to, using a textfield, a label, and a button, take the user's input and feed it out through the label. But I understand, from previous questions, that properties are like the addresses of certain objects, not the actual objects.

It would be awesome if someone could just show me how to take the user input from one textfield and multiply by the user input from another textfield, just so I can see how to do this.

Here are both files:

//  ViewController.h
//  Cramer

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController

// Objects are given addresses:


@property (weak, nonatomic) IBOutlet UITextField *box_a;
@property (weak, nonatomic) IBOutlet UITextField *box_b;
@property (weak, nonatomic) IBOutlet UILabel *hiLabel;

@property (weak, nonatomic) IBOutlet UIButton *clickButton;

@end

AND

//
//  ViewController.m
//  Cramer

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

// When button is clicked, user input from textfield is fed out through label:

- (IBAction)clickButton:(id)sender {

    NSInteger number1 = [self.box_a.text integerValue];
    NSInteger number2 = [self.box_b.text integerValue];

    NSInteger prod = number1 * number2;

    self.hiLabel.text = [NSString stringWithFormat:"%@", @(prod)];

}

@end

Both errors are on self.hiLabel line

Upvotes: 0

Views: 134

Answers (1)

AndrewShmig
AndrewShmig

Reputation: 4923

Something like this:

NSInteger number1 = [self.textField1.text integerValue];
NSInteger number2 = [self.textField2.text integerValue];

NSInteger prod = number1 * number2;

To set prod value in UILabel or UITextField:

self.textField1.text = [NSString stringWithFormat:@"%@", @(prod)];

Upvotes: 1

Related Questions