Welcome, Guest. Please login or register.
Did you miss your activation email?
July 30, 2016, 04:10:11 AM
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
Author Topic: Weird breakpoint on program 6.8 (Read 1475 times)
Posts: 2

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;

@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;


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...");
        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
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

Then the breakpoint hits and highlights the setAccumulator method.

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



PS. Apologies if this is in the wrong place... mea culpa.
Posts: 2

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!!!


Pages: [1] Go Up
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.