empi99
empi99

Reputation: 15

Metric Conversion Calculator in xcode

Does anyone know how to take a numeric entry and put it through a formula? I'm trying to create a conversion calculator for millimeters to inches, with a switch that changes the formula so you can calculate inches to millimeters. so far, this is what i have done, and I'm using xcode 3.2.6

.m

@synthesize entry;
@synthesize output;
@synthesize toggle;

//-(IBAction)hidekeyboard:(id)sender{

-(IBAction)calculate:(id)sender{
    float floatoutput=[entry.text floatValue]/[25.4];
}

.h

    IBOutlet UITextField *entry;
    IBOutlet UILabel *output;
    IBOutlet UISwitch *toggle;
}

-(IBAction)calculate:(id)sender;
-(IBAction)hidekeyboard:(id)sender;

@property (nonatomic, retain) UITextField *entry;
@property (nonatomic, retain) UILabel *output;
@property (nonatomic, retain) UISwitch *toggle;

I'm very new to xcode and any information you could give me would be very much appreciated.

Upvotes: 0

Views: 618

Answers (2)

El Tomato
El Tomato

Reputation: 6705

Something like the following?

- (float)conver2inches: (NSString *)mmeters {
    return [mmeters floatValue]/25.4f;
}

-(IBAction)calculate:(id)sender{
    float answer = [self conver2inches:entry.text];
    textfield1.text = [NSString stringWithFormat:@"%f",answer];
}

Upvotes: 1

Anoop Vaidya
Anoop Vaidya

Reputation: 46563

You are doing it wrong :

It should be as :

float floatoutput=[entry.text floatValue]/25.4;

[ ] is used for method calls or for subscripting of array. You need not write [25.4] which makes no-sense.

*And make a note 25.4 is not float, it is double you should use 25.4f

Upvotes: 0

Related Questions