[Solved] Adding five Numbers Entered as Strings in Textfields [closed]


You Have To First Add 5 TextField, 1 Label For Output Result, And One Button.
and Make to create that outlet.. like this… in
Do it in your .h File

@property (weak, nonatomic) IBOutlet UITextField *txtField1;
@property (weak, nonatomic) IBOutlet UITextField *txtField2;
@property (weak, nonatomic) IBOutlet UITextField *txtField3;
@property (weak, nonatomic) IBOutlet UITextField *txtField4;
@property (weak, nonatomic) IBOutlet UITextField *txtField5;
@property (weak, nonatomic) IBOutlet UILabel *lblForResult;
- (IBAction)AddButtonClicked:(id)sender;

the button is IbAction For Clicking Event
Ann do it from your .m File
Addbutton Clicked Event.. or your Button Click Event….

- (IBAction)AddButtonClicked:(id)sender {
    int val1=[self.txtField1.text intValue];
    int val2=[self.txtField2.text intValue];
    int val3=[self.txtField3.text intValue];
    int val4=[self.txtField4.text intValue];
    int val5=[self.txtField5.text intValue];
    int result=val1+val2+val3+val4+val5;
    self.lblForResult.text=[NSString stringWithFormat:@"%d",result];
}

OR YOU CAND DO LIKE THIS INSTEAD OF DECLARING THE FIVE VARIABLE….

- (IBAction)AddButtonClicked:(id)sender {
 int result=[self.txtField1.text intValue]+[self.txtField2.text intValue]+[self.txtField3.text intValue]+[self.txtField4.text intValue]+[self.txtField5.text intValue];
    self.lblForResult.text=[NSString stringWithFormat:@"%d",result];
}

1

solved Adding five Numbers Entered as Strings in Textfields [closed]