Alright. My app has a text field and next to it are two buttons (Plus button and Equals button). When you press the "Plus" button, it takes the text inside of the textField and adds a "+" to it. Code below:
- (IBAction)plusButtonPressed:(id)sender {
NSString *plusString = @"+";
NSString *inputString = carbsField.text;
NSString *outputString = [NSString stringWithFormat:@"%@%@",inputString,plusString];
NSLog(@"%@",outputString);
[carbsField setText:outputString];
}
I will eventually make that more intelligent so that I can't put two pluses or whatever. Anyway, then I want the equal button to take whatever is in the textField, which should look something like: "23+54+2.2" and get the sum of those values. I believe I know how to take an Integer and make it a String, but I want to verify it:
int *value = 56;
NSString *string = @"%d",value;
Well, if anyone can show me how to do this, I would be very appreciative. Thanks.
EDIT
At the moment, I have not tried anything. This is because I do not know where to start. I have an idea of what to do, but I do not know how to execute it. I believe I need to get all characters before a "+" convert them into int and then get the sum of some array of those values.