I’m following this tutorial I found online on how to make a calculator in xcode. I am using version 3.2.6 of xcode and here is the function that is giving me problems:
-(IBAction) calculate
{
float x= ([textField1.text floatValue]);
float c= x*([textField2.text floatValue]);
label.text = [[NSString alloc] initWithFormat:@"%2.f", c];
}
I get these compiler errors on the line with label.text:
Expected ‘:’ before ‘;’ token and confused about earlier errors bailing out.
Any ideas on what could be wrong? Do I have to include a special header file to use initWithFormat? or is this a syntax error?
Make sure you don’t have an invisible character in there somewhere.
I frequently end up with the wrong kind of line ending. The easiest way to tell is put your cursor on a line and hit ctrl-a. If the cursor bounces to the beginning of the previous line, it is an incorrect line ending. Delete the line ending and hit return.
(In my case, it is due to a bit of neural hardwiring resulting from 20 years of emacs usage)