Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
January 23, 2018, 09:09:13 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register Chat  
Pages: [1]   Go Down
  Print  
Author Topic: Does anyone see an error in this code?  (Read 1566 times)
wmHow
Newbie
*
Posts: 19


« on: October 22, 2009, 09:49:22 PM »

I noticed I posted this in Part 1 by mistake:

I'm getting an "expected identifier before "-" token" error in each of these code sections.
I have gone over them over and over and don't see an error.  In the past, other users have compiled code cleanly that I get messages on.  Does this happen to anyone else?  Can you get hidden characters in your code that cause you to get errors that throw you off?  Any help would be appreciated.

Mark



#import "Fraction_CalculatorAppDelegate.h"
#import "Fraction_CalculatorViewController.h"

@implementation Fraction_CalculatorAppDelegate

@synthesize window;
@synthesize viewController;

-(void)applicationDidFinishLaunching:(UIApplication *) application {
   //Overide point for customization after app launch
   [window addSubview:viewController.view];
   [window makeKeyAndVisible];
}

-(void)dealloc  {
   [viewController release];
   [super dealloc];
}

@end




#import "Fraction_CalculatorViewController.h"
@implementation Fraction_CalculatorViewController

@synthesize display, displayString;


-(void) viewDidLoad {
   // Override point for customization after application launch
   
   firstOperand = YES;
   isNumerator = YES;
   self.displayString = [NSMutableString stringWithCapacity: 40];
   myCalculator = [[Calculator alloc] init];
}

-(void) processDigit: (int) digit
{
   currentNumber = currentNumber * 10 + digit;
   
   [displayString appendString: [NSString stringWithFormat: @"%i", digit]];
   [display setText: displayString];
}

-(IBAction) clickDigit:(id)sender
{
   int digit = [sender  tag];
   [self processDigit:digit];
}   

-(void) processOp: (char) theOp
{
   NSString *opStr;
   
   op = theOp;
   
   switch (theOp)  {
      case '+':
         opStr = @" + ";
         break;
      case '-':
         opStr = @" - ";
         break;
      case '*':
         opStr = @" x ";
         break;
      case '/':
         opStr = @"   ";
         break;
   }
   
   [self storeFracPart]; 
   firstOperand = NO;
   isNumerator = YES;
   
   [displayString appendString: opStr];
   [display setText: displayString];
}

-(void) storeFracPart
{
   if (firstOperand) {
      if (isNumerator) {
         myCalculator.operand1.numerator = currentNumber;
         myCalculator.operand1.denominator = 1; // e.g. 3 * 4/5 =
      }
      else
         myCalculator.operand1.denominator = currentNumber;
   }
   else if (isNumerator) {
      myCalculator.operand2.numerator = currentNumber;
      myCalculator.operand2.denominator = 1; // e.g. 3/2 * 4 =
   }
   else {
      myCalculator.operand2.denominator = currentNumber;
      firstOperand = YES;
   }
   
   currentNumber = 0;
}

-(IBAction) clickOver: (id) sender
{
   [self storeFracPart];
   isNumerator = NO;
   [displayString appendString: @"/"];
   [display setText: displayString];
}

//Arithmetic Operation Keys

-(IBAction) clickPlus: (id) sender
{
   [self processOp: '+'];
}

-(IBAction) clickMinus: (id) sender
{
   [self processOp: '-'];
}

-(IBAction) clickMultiply: (id) sender
{
   [self processOp: '*'];
}

-(IBAction) clickDivide: (id) sender
{
   [self processOp: '/'];
}

//Misc. Keys

-(IBAction) clickEquals: (id) sender
{
   [self storeFracPart];
   [myCalculator performOperation: op];
   [displayString appendString: @" = "];
   [displayString appendString: [myCalculator.accumulator convertToString]];
   [display setText: displayString];
   
   currentNumber = 0;
   isNumerator = YES;
   firstOperand = YES;
   [displayString setString: @""];
}

-(IBAction) clickClear: (id) sender
{
   isNumerator = YES;
   firstOperand = YES;
   currentNumber = 0;
   [myCalculator clear];

     
   [displayString setString: @""];
   [display setText: displayString];
}


- (void)dealloc {
   [myCalculator dealloc];
    [super dealloc];
}

@end

Logged
rgronlie
Global Moderator
Full Member
*****
Posts: 212



« Reply #1 on: October 22, 2009, 11:27:51 PM »

Mark,

The problem might be in one of the .h files.

Probably Fraction_CalculatorViewController.h or another .h that gets imported from that one.

Ryan
Logged

Sanity: Minds are like parachutes. Just because you've lost yours doesn't mean you can borrow mine.
wmHow
Newbie
*
Posts: 19


« Reply #2 on: October 24, 2009, 03:24:55 PM »

Thanks Ryan for your help.  I will check it out.

Mark
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

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 ゥ 2009 classroomM.com. All rights reserved.