Hi,
I am just getting started in ObjC but I can't get the following program to build (2 build errors in Xcode) but I don't see anything wrong with the code. What am I missing?
Really frustrating as I am sure it is only a really small thing!
Thanks,
MadDoc
I am just getting started in ObjC but I can't get the following program to build (2 build errors in Xcode) but I don't see anything wrong with the code. What am I missing?
Code:
// Implement a calculator class
#import <objc/Object.h>
#import <stdio.h>
// ---------- Interface section ---------- \\
@interface Calculator: Object
{
double accumulator; // stores the current total
}
// 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 section ---------- \\
@implementation Calculator;
// Accumulator methods
-(void) setAccumulator: (double) value
{
accumulator = value;
}
-(void) clear
{
accumulator = 0;
}
-(double) accumulator
{
return accumulator;
}
// Arithmetic methods
-(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
// ---------- Program section ---------- \\
int main (int argc, char *argv[])
{
// Create a new calculator
Calculator *deskCalc;
deskCalc = [[Calculator alloc] init];
// Clear the calculator
[deskCalc clear];
// Set the accumulator to 100
[deskCalc setAccumulator:100];
// Add 200
[deskCalc add: 200];
// Print the result
printf("\nThe value of the accumulator is: %f\n", [deskCalc accumulator]);
}
Really frustrating as I am sure it is only a really small thing!
Thanks,
MadDoc