Quote:
Originally Posted by mayspanky
Hello All,
We are creating another page for our app (bowlingcalc). The equations are set except the only answer that works is q (label5). Not sure why the others are not computing  . Any help would greatly be appreciated.
Code:
-(IBAction)calculate {
//Percentage
float o = ([textField11.text floatValue]);
float p = -.5;
//Difference
float q = ([label5.text floatValue]);
//Team 1
float a = ([textField.text floatValue]);
float b = ([textField2.text floatValue]);
float c = ([textField3.text floatValue]);
float d = ([textField4.text floatValue]);
float e = ([textField5.text floatValue]);
//Team 1 Totals
float f = ([label.text floatValue]);
float g = ([label2.text floatValue]);
//Team 2
float h = ([textField6.text floatValue]);
float i = ([textField7.text floatValue]);
float j = ([textField8.text floatValue]);
float k = ([textField9.text floatValue]);
float l = ([textField10.text floatValue]);
//Team 2 Totals
float m = ([label3.text floatValue]);
float n = ([label4.text floatValue]);
//Team 1
f = a+b+c+d+e;
label.text = [[NSString alloc] initWithFormat:@"%2.0f"];
g = f*o;
label2.text = [[NSString alloc] initWithFormat:@"%2.0f"];
//Team 2
m = h+i+j+k+l;
label3.text = [[NSString alloc] initWithFormat:@"%2.0f"];
n = m*o;
label4.text = [[NSString alloc] initWithFormat:@"%2.0f"];
//Difference
q = ((a + b + c + d + e) - (h + i + j + k + l))*(0.01)*(o)+ p;
label5.text = [[NSString alloc] initWithFormat:@"%2.0f" , round(q)];
|
You don't give enough information for your post to make sense to anybody but you.
What does your app do? What information does it collect. What results is it supposed to show?
What do the contents of all the text fields mean? What about the labels?
Without knowing any of that, I can see that your assignments to label1.text through label4.text are invalid. You use initWithFormat, and have a floating point format in your format string, but don't pass in the value you want to format.
Take the first one for example:
Code:
f = a+b+c+d+e;
label.text = [[NSString alloc] initWithFormat:@"%2.0f"];
Assuming that you want "label" to contain the value of "f", it should read like this:
Code:
f = a+b+c+d+e;
label.text = [NSString stringWithFormat:@"%2.0f", f];
Note that I rewrote it to use stringWithFormat, not initWithFormat. When you use initWithFormat, you get back an "owning reference" to the string.
I believe that a UILabel object's text property is set up as copy, so it's going to create a copy of your string as keep the copy. You're original string will be abandoned, and leaked.
The "stringWithFormat" method returns an autoreleased object, which will get released automatically on the next pass through the event loop.
It looks to me like you're pretty lost, and asking for really basic "how do I write hello world" type help. The advanced discussion board is not the place for you.