Amazon.com Widgets Weird breakpoint on program 6.8
Welcome, Guest. Please login or register.
Did you miss your activation email?
October 22, 2014, 04:01:57 PM
Home Help Search chat Login Register 
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan
                     

+ Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+ Old Stuff
| |-+ Program Examples
| | |-+ Chapter 6
| | | |-+ Weird breakpoint on program 6.8
Pages: [1] Go Down
Print
Author Topic: Weird breakpoint on program 6.8 (Read 1022 times)
Skyglass
Newbie
*
Posts: 2


Email




on: June 06, 2011, 06:58:01 PM

I'm taking my time and typing in all the programs from the chapters to really focus my attention on what's going on with each line. It's slow, but effective so far.

I'm getting an odd breakpoint when trying to run Program 6.8. I've made some changes to it, but the parser and build show me no errors. However, when I've entered in the values for the scanf statement (or if I simply define them in the program itself and skip the scanf statement, the debug stops at the setAccumulator method every time!

Can someone explain to me what's going on? I'm baffled...


Code: (Objective-C)
//
//  main.m
//  Program 6
//
//  Created by John Gaffney on 6/3/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//
// Program to evaluate simple expressions of the form
//    number  expression  number

// Implement a Calculator class

#import <Foundation/Foundation.h>
@interface Calculator: NSObject
{
    double accumulator;
}

// Accumulator methods

-(void) setAccumulator: (double) value;
-(void) clear;
-(double) accumulator;

// Arithmetic methods

-(void) add: (double) value;
-(void) subtract: (double) value;
-(void) multiply: (double) value;
-(void) divide: (double) value;
@end

@implementation Calculator

-(void) setAccumulator: (double) value {
    accumulator = value;
}

-(void) clear{
    accumulator = 0;
}

-(double) accumulator {
    return accumulator;
}

-(void) add: (double) value {
    accumulator += value;
}
   
-(void) subtract: (double) value {
    accumulator -= value;
}

-(void) multiply: (double) value {
    accumulator *= value;
}
-(void) divide: (double) value {
    accumulator /= value;
}

@end

int main (int argc, const char * argv[])
{

    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

    double value1, value2;
    char operator;
    Calculator *deskCalc = [[Calculator alloc] init];
    [deskCalc clear];
    NSLog(@"Type in your expression");
    scanf("%lf%c%lf", &value1, &operator, &value2);
//    value1 = 3;
//    operator = 'x';
//    value2 = 2;
    NSLog(@"value1 is %lf", value1);
    NSLog(@"operator is %c", operator);
    NSLog(@"value2 is %lf", value2);
   
    [deskCalc setAccumulator: value1];
   
    if (operator == '+')
        [deskCalc add: value2];
    else if (operator == '-')
        [deskCalc subtract: value2];
    else if (operator == 'x' || operator == '*')
        [deskCalc multiply: value2];
    else if (operator == '/' && value2 != '0')
        [deskCalc divide: value2];
    else if (operator == '/' && value2 == '0')
    {
        NSLog(@"You cannot divide by zero, you ninny!");
        NSLog(@"/n The program quits in disgust...");
    }
    else
        NSLog(@"I don't know how to do that, sorry!");
   
    NSLog(@"%.2f", [deskCalc accumulator]);
    [deskCalc release];
       
    [pool drain];
    return 0;
}
   

My console window shows the following:
2011-06-06 21:39:08.159 Program 6[27006:903] Type in your expression
2-3
2011-06-06 21:39:12.639 Program 6[27006:903] value1 is 2.000000
2011-06-06 21:39:12.640 Program 6[27006:903] operator is -
2011-06-06 21:39:12.640 Program 6[27006:903] value2 is 3.000000
(gdb)


Then the breakpoint hits and highlights the setAccumulator method.

I'm using XCode 4.0.2 if it makes a difference...

Thanks,

John

PS. Apologies if this is in the wrong place... mea culpa.
Logged
Skyglass
Newbie
*
Posts: 2


Email




Reply #1 on: June 06, 2011, 07:06:51 PM

I is moron.

I no know breakpoints.

Me very sorry.

Me no realize breakpoints on by default in newly installed XCode 4.0.2.

Mea MAXIMA culpa!!!

TWO HOURS OF MY LIFE GONE!

*sigh*
Logged
Pages: [1] Go Up
Print
Jump to:



Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents (c) 2009 classroomM.com. All rights reserved.