Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Selection Issues with xCode

  • 25-01-2010 9:16pm
    #1
    Registered Users, Registered Users 2 Posts: 99 ✭✭


    I'm beginning to learn Objective C & am using xCode to build basic learner applications
    I've started with a basic calc app that has a button "ADD" and two hard coded numbers; 2 & 3.

    When I click the button, the result (stored as float) is output to a label correctly, as 5.00000.

    However, when I introduce an if statement (to allow for additional buttons) which performs different arithmetic depending on the ID of the sender, the math goes out the window.

    With no addition to the above, except for putting it in an IF statement, the result of the calculation is displayed as -1.998977. I've outlined the implementation code below.

    Can anyone suggest what I might be missing??

    int num_1 = 3;
    int num_2 = 2;
    float result_Num;

    if (sender == addition)
    result_Num = num_1 + num_2;

    NSString *resultString = [[NSString alloc] initWithFormat:
    @%f, result_Num];

    result_Text.text = resultString;
    [resultString release];

    (note that all relevant objects are synthesised & release appropriately (at least according to instructions that I have read!!) :-)


Comments

  • Registered Users, Registered Users 2 Posts: 7,182 ✭✭✭Genghiz Cohen


    I could be that the IF never hits and skips over the init of result_Num.
    So you never actually init result_Num and it outputs garbage.
    Slap a breakpoint on the line "result_Num = num_1 + num_2;" and see if it hits.
    Also, init all variables to something, even 0.


Advertisement