April 22, 2018, 09:05:37 AM
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email?
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Read this please.
♦
The Great Kangaroo Escape
♦
Looking for reviews of the 4th ed on Amazon!
♦
Twitter:
@skochan
Home
Help
Search
Login
Register
Chat
Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
>
Old Stuff
>
Webcast Series Part II, Oct. 1 - 27
>
Questions and Discussion
>
Does anyone see an error in this code?
Pages: [
1
]
Go Down
« previous
next »
Print
Author
Topic: Does anyone see an error in this code? (Read 1614 times)
wmHow
Newbie
Posts: 19
Does anyone see an error in this code?
«
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
Re: Does anyone see an error in this code?
«
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
Re: Does anyone see an error in this code?
«
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
« previous
next »
Jump to:
Please select a destination:
-----------------------------
Programming in Objective-C, 5th edition
-----------------------------
=> General Discussions
=> Exercises
-----------------------------
Programming in Objective-C, 4th edition
-----------------------------
=> General Discussion
=> Exercises
===> Chapter 2
===> Chapter 3
===> Chapter 4
===> Chapter 5
===> Chapter 6
===> Chapter 7
===> Chapter 8
===> Chapter 9
===> Chapter 10
===> Chapter 11
===> Chapter 12
===> Chapter 13
===> Chapter 14
===> Chapter 15
===> Chapter 16
===> Chapter 17
===> Chapter 18
===> Chapter 19
===> Chapter 20
===> Chapter 21
=> Chapter 2
=> Chapter 3
=> Chapter 4
=> Chapter 5
=> Chapter 6
=> Chapter 7
=> Chapter 8
=> Chapter 9
=> Chapter 10
=> Chapter 11
=> Chapter 12
=> Chapter 13
=> Chapter 14
=> Chapter 15
=> Chapter 16
=> Chapter 17
=> Chapter 18
=> Chapter 19
=> Chapter 20
=> Chapter 21
=> Errata
===> 1st Printing
===> 2nd Printing
-----------------------------
Members' Corner
-----------------------------
=> Look What I'm Doing...
-----------------------------
Study Group
-----------------------------
=> Objective-C Quizzes
===>
Comprehensive Quiz
===> Chapter 1 - Introduction
===> Chapter 2 - Programming in Objective-C
===> Chapter 3 - Classes, Objects, and Methods
===> Chapter 4 - Data Types and Expressions
===> Chapter 5 - Program Looping
===> Chapter 6 - Making Decisions
===> Chapter 7 - More on Classes
===> Chapter 8 - Inheritance
===> Chapter 9 - Polymorphism, Dynamic Typing, and Dynamic Binding
===> Chapter 10 - More on Variables and Data Types
===> Chapter 11 - Categories and Protocols
===> Chapter 12 - The Preprocessor
===> Chapter 15 - Numbers, Strings & Collections
===> Chapter 17 - Memory Management
-----------------------------
iOS Programming
-----------------------------
=> General Questions
-----------------------------
Programming in C, 3rd ed. (Stephen Kochan)
-----------------------------
=> Programming in C webcasts?
=> Answers to Odd-Numbered Exercises
=> Questions and Help
-----------------------------
Old Stuff
-----------------------------
=> Errata, Answers to Exercises, Code, etc.
=> Shared Code Library
=> Welcome
=>
News
=> Errata
===> 1st Printing
===> 2nd printing
=> Newbie Corner
=> Chapter Study
===> Chapter 2 - Programming in Objective-C
===> Chapter 3 - Classes, Objects, and Methods
===> Chapter 4 - Data Types and Expressions
===> Chapter 5 - Program Looping
===> Chapter 6 - Making Decisions
===> Chapter 7 - More on Classes
===> Chapter 8 - Inheritance
===> Chapter 9 - Polymorphism, Dynamic Typing, and Dynamic Binding
===> Chapter 10 - More on Variables and Data Types
===> Chapter 11 - Categories and Protocols
===> Chapter 12 - The Preprocessor
===> Chapter 13 - Underlying C Language Features
===> Chapter 15 - Numbers, Strings, and Collections
===> Chapter 16 - Working with Files
===> Chapter 17 - Memory Management
===> Chapter 18 - Copying Objects
===> Chapter 19 - Archiving
===> Chapter 21 - Writing iPhone Applications
=> Answers to Exercises
===> Chapter 2
===> Chapter 3
===> Chapter 4
===> Chapter 5
===> Chapter 6
===> Chapter 7
===> Chapter 8
===> Chapter 9
===> Chapter 10
===> Chapter 11
===> Chapter 12
===> Chapter 13
===> Chapter 15
===> Chapter 16
===> Chapter 17
===> Chapter 18
===> Chapter 19
===> Chapter 21
=> General Discussion
=> Program Examples
===> Chapter 2
===> Chapter 3
===> Chapter 4
===> Chapter 5
===> Chapter 6
===> Chapter 7
===> Chapter 8
===> Chapter 9
===> Chapter 10
===> Chapter 11
===> Chapter 12
===> Chapter 13
===> Chapter 15
===> Chapter 16
===> Chapter 17
===> Chapter 18
===> Chapter 19
===> Chapter 21
=> XCode 4 Help
=> Suggestions
=> Help!!!
=> Fraction Calculator Available from the App Store
=> Resources
=> Errata
===> 1st & 2nd printings
===> 3rd & 4th printings
===> 5th printing
===> Current Errata
=> Suggestion Box
=> Tips & Tricks
=> Part 3
===> Welcome to the Class
===>
Special Announcements
===> Assignments
=> Parts 1 and 2
===> Welcome to the Class
===> Questions and Discussion
===>
SPECIAL ANNOUNCEMENTS
===> Assignments
===> Chapter 4, Exercise 7
===> Suggestions
=> Webcast Series Part I, Sept. 1 - 24
===> Welcome
===>
SPECIAL ANNOUNCEMENTS
===> Questions and Discussion
===> Assignments
===> Chapter 4, Exercise 7
===> Chapter 6, Exercise 4
===> Suggestions
=> Webcast Series Part II, Oct. 1 - 27
===> Welcome
===>
SPECIAL ANNOUNCEMENTS
===> Questions and Discussion
===> Assignments
===> Example using hasPrefix: and hasSufix:
===> Suggestions
=> Objective-C Workshop Aug 11 - 13
=> Webcast Series Part I, Oct. 29 - Dec. 1
===> Welcome
===>
SPECIAL ANNOUNCEMENTS
===> Assignments
===> Chapter 4, Exercise 7
===> Chapter 6, Exercise 4
===> Suggestions
=> Webcast Series Part II, Jan 5 - 28
===> Welcome
===>
SPECIAL ANNOUNCEMENTS
===> Assignments
===> Jan 7th Solutions
Loading...