Hi I'm writing my very first program with a GUI right now, a simple calculator app. I have fixed all issues the compiler came with except that after the #import I get an error message like this:
error: syntax error before '=' token
error: syntax error before '=' token
error: syntax error before '=' token
error: syntax error before '=' token
Here is my @interface:
Here is the @implementation:
Thank you in advance,
Ben.
error: syntax error before '=' token
error: syntax error before '=' token
error: syntax error before '=' token
error: syntax error before '=' token
Here is my @interface:
Code:
#import <Cocoa/Cocoa.h>
@interface BECalculator : NSObject {
IBOutlet id textField;
NSString *theOutput;
double firstNumber = 0;
double secondNumber = 0;
double theResult;
}
- (IBAction)add:(id)sender;
- (IBAction)divide:(id)sender;
- (IBAction)equals:(id)sender;
- (IBAction)multiply:(id)sender;
- (IBAction)setFirstNumberTo1:(id)sender;
- (IBAction)setFirstNumberTo2:(id)sender;
- (IBAction)setFirstNumberTo3:(id)sender;
- (IBAction)setFirstNumberTo4:(id)sender;
- (IBAction)setFirstNumberTo5:(id)sender;
- (IBAction)setFirstNumberTo6:(id)sender;
- (IBAction)setFirstNumberTo7:(id)sender;
- (IBAction)setFirstNumberTo8:(id)sender;
- (IBAction)setFirstNumberTo9:(id)sender;
- (IBAction)subtract:(id)sender;
@end
Here is the @implementation:
Code:
#import "BECalculator.h"
[COLOR="SeaGreen"]//It is here I get the error message.[/COLOR]
@implementation BECalculator
- (IBAction)add:(id)sender
{
theOutput = [NSString stringWithString: @"+"];
}
- (IBAction)divide:(id)sender
{
theOutput = [NSString stringWithString: @"/"];
}
- (IBAction)equals:(id)sender
{
if (theOutput == @"+")
theResult = firstNumber + secondNumber;
else if (theOutput == @"-")
theResult = firstNumber - secondNumber;
else if (theOutput == @"*")
theResult = firstNumber * secondNumber;
else if (theOutput == @"/")
theResult = firstNumber / secondNumber;
[textField setDoubleValue: theResult];
}
- (IBAction)multiply:(id)sender
{
theOutput = [NSString stringWithString: @"*"];
}
- (IBAction)setFirstNumberTo1:(id)sender
{
if (firstNumber =! 0)
secondNumber = 1;
else
firstNumber = 1;
}
- (IBAction)setFirstNumberTo2:(id)sender
{
if (firstNumber =! 0)
secondNumber = 2;
else
firstNumber = 2;
}
- (IBAction)setFirstNumberTo3:(id)sender
{
if (firstNumber =! 0)
secondNumber = 3;
else
firstNumber = 3;
}
- (IBAction)setFirstNumberTo4:(id)sender
{
if (firstNumber =! 0)
secondNumber = 4;
else
firstNumber = 4;
}
- (IBAction)setFirstNumberTo5:(id)sender
{
if (firstNumber =! 0)
secondNumber = 5;
else
firstNumber = 5;
}
- (IBAction)setFirstNumberTo6:(id)sender
{
if (firstNumber =! 0)
secondNumber = 6;
else
firstNumber = 6;
}
- (IBAction)setFirstNumberTo7:(id)sender
{
if (firstNumber =! 0)
secondNumber = 7;
else
firstNumber = 7;
}
- (IBAction)setFirstNumberTo8:(id)sender
{
if (firstNumber =! 0)
secondNumber = 8;
else
firstNumber = 8;
}
- (IBAction)setFirstNumberTo9:(id)sender
{
if (firstNumber =! 0)
secondNumber = 9;
else
firstNumber = 9;
}
- (IBAction)subtract:(id)sender
{
theOutput = [NSString stringWithString: @"-"];
}
@end
Thank you in advance,
Ben.