-When I call-in my strings the data is not computing and I receive errors. Is it my coding (as seen below)? Is it possible to have 3 fields of data and the ans be the sum of the lowest 2 integers of the 3? This is killing my brain. (I’ve declared the optional integers for X,Y,Z) HELP! Thank you.
-(I’m synthesizing 2 separate TextFields (last,second,&third) and the same goes for labels and strings. I am also synthesizing the final field where the calculation should appear and that is totalTextField, totalLabel, totalString).
#import "EquationViewController.h"
@implementation EquationViewController
@synthesize lastTextField, lastLabel, lastString;
@synthesize secondLastTextField, secondLastLabel, secondLastString;
@synthesize thirdLastTextField, thirdLastLabel, thirdLastString;
@synthesize totalTextField, totalLabel, totalString;
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)viewWillAppear:(BOOL)animated
{
lastLabel.text = lastString;
secondLastLabel.text = secondLastString;
thirdLastLabel.text = thirdLastString;
}
- (void) viewWillDisappear:(BOOL) animated
{
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
lastLabel.text = [[NSString alloc] initWithFormat:@"Last", lastTextField.text];
secondLastLabel.text = [[NSString alloc] initWithFormat:@"2nd Last", secondLastTextField.text];
thirdLastLabel.text = [[NSString alloc] initWithFormat:@"3rd Last", thirdLastTextField.text];
totalLabel.text = [[NSString alloc] initWithFormat:@"Total", totalTextField.text];
#include <stdio.h>
int main ();
{
double X,Y,Z,ans;
X = 3;
Y = 1.5;
Z = 99;
ans = (X+Y+Z) - MAX(X,MAX(Y,Z));
Well, if I got the problem you’d like to have the sum of the lowest two integer printed out (I didn’t understand if in a textField or in a label).
These three numbers should be set by the user in
lastTextField,secondTextFieldandthirdTextField.If this is correct (and the delegate is set properly for all the textFields) you can perform your operation in your
- (void)textFieldDidEndEditing:(UITextField *)textFieldmethod.To get the value in the textField you can call the
intValuemethod of thetextproperty of the textField, i.e.(the same way you can call
doubleValue,floatValueand so on).This way you can access the values in the textFields.
To update the final result you should call the
setText:method oftotalTextField(the method is the same if you want to updatetotalLabel). i.e. if you saved your result in a int calledres, you can callHope it helps