Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development > iPhone SDK Development - Advanced Discussion

Reply
 
LinkBack Thread Tools Display Modes
Old 11-08-2011, 10:36 AM   #1 (permalink)
CNJ Apps
 
Join Date: Nov 2011
Location: US
Posts: 1
mayspanky is on a distinguished road
Default HELP with Math string

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)];
mayspanky is offline   Reply With Quote
Old 11-12-2011, 08:50 PM   #2 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,002
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by mayspanky View Post
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.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 11-17-2011, 04:21 PM   #3 (permalink)
Registered Member
 
Join Date: Dec 2010
Location: Seattle, WA
Posts: 408
RickSDK is on a distinguished road
Default

I see the problem... you are not including the varable in your lines:

label.text = [[NSString alloc] initWithFormat:@"%2.0f"];


you have %2.0f with no reference to any variable
RickSDK is offline   Reply With Quote
Old 11-17-2011, 04:24 PM   #4 (permalink)
Registered Member
 
Join Date: Dec 2010
Location: Seattle, WA
Posts: 408
RickSDK is on a distinguished road
Default

also, there's no reason for you to be allocating strings in this way and thus creating memory leaks in your code. just use stringWithFormat:

label.text = [NSString stringWithFormat:@"%2.0f", value];
RickSDK is offline   Reply With Quote
Old 11-22-2011, 09:00 PM   #5 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,002
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by RickSDK View Post
I see the problem... you are not including the varable in your lines:

label.text = [[NSString alloc] initWithFormat:@"%2.0f"];


you have %2.0f with no reference to any variable

There's an echo in here.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 11-22-2011, 09:01 PM   #6 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,002
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by RickSDK View Post
also, there's no reason for you to be allocating strings in this way and thus creating memory leaks in your code. just use stringWithFormat:

label.text = [NSString stringWithFormat:@"%2.0f", value];

There's an echo in here...

There's an echo in here...

There's an echo in here...........


__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 384
9 members and 375 guests
bignoggins, djqbert, epaga, hussain1982, jcdevelopments, LunarMoon, markolo, omagod, pinacate
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,644
Threads: 94,110
Posts: 402,860
Top Poster: BrianSlick (7,990)
Welcome to our newest member, djqbert
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 04:57 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0