Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

Calc/Classes/CalcViewController.m:164: error: expected identifier or '(' before 'switch'

Can anybody explain me what is the reason behind this error..?
Thanks in advance.

#import "CalcViewController.h"
@implementation CalcViewController
@synthesize textField1;
@synthesize button1;
@synthesize button2;
@synthesize button3;
@synthesize button4;
@synthesize button5;
@synthesize button6;
@synthesize button7;
@synthesize button8;
@synthesize button9;
//@synthesize button0;
@synthesize pls;
@synthesize mns;
@synthesize mul;
@synthesize div;
@synthesize back_space;
@synthesize equals;
@synthesize cancel;
@synthesize decimal_point;
//@synthesize button2;
//NSString result;
//NSString currentNumber = @"0";
//int iNumber;
int operator=0;
int first;
int second;
//NSString *myString = @"9";// = [NSString string];
/*
-(IBAction) Plus:(id)sender
{
	textField1.text=@"0";
}*/
-(IBAction) b0:(id)sender
{
	//iNumber = [currentNumber intValue];
	//iNumber = iNumber * 10 + 0;
	
	myString = [myString stringByAppendingString:@"0"];//textField1.text;//, intValue];
	textField1.text=myString;
	//currentNumber=currentNumber * 10 + 0;
	//NSString* myNewString = [NSString stringWithFormat:@"%f", currentNumber];
	//textField1.text= [NSString stringWithFormat:@"%@",myString];
	
	
}
-(IBAction) b1:(id)sender
{
	myString=[myString stringByAppendingString:@"1"];
	textField1.text=myString;
	//currentNumber=currentNumber * 10 + 1;
	//NSString* myNewString = [NSString stringWithFormat:@"%f", currentNumber];
	//textField1.text= [NSString stringWithFormat:@"%@",myString];
}
-(IBAction) b2:(id)sender
{
	myString=[myString stringByAppendingString:@"2"];
	textField1.text=myString;
	//currentNumber=currentNumber * 10 + 2;
	//NSString* myNewString = [NSString stringWithFormat:@"%f", currentNumber];
	//textField1.text= myNewString;
}
-(IBAction) b3:(id)sender
{
	myString=[myString stringByAppendingString:@"3"];
	textField1.text=myString;
	/*currentNumber=currentNumber * 10 + 3;
	NSString* myNewString = [NSString stringWithFormat:@"%f", currentNumber];
	textField1.text= myNewString;*/
}
-(IBAction) b4:(id)sender
{
	myString=[myString stringByAppendingString:@"4"];
	textField1.text=myString;
	/*currentNumber=currentNumber * 10 + 4;
	NSString* myNewString = [NSString stringWithFormat:@"%f", currentNumber];
	textField1.text= myNewString;*/
}
-(IBAction) b5:(id)sender
{
	myString=[myString stringByAppendingString:@"5"];
	textField1.text=myString;
	/*currentNumber=currentNumber * 10 + 5;
	NSString* myNewString = [NSString stringWithFormat:@"%f", currentNumber];
	textField1.text= myNewString;*/
}
-(IBAction) b6:(id)sender
{
	myString=[myString stringByAppendingString:@"6"];
	textField1.text=myString;
	/*currentNumber=currentNumber * 10 + 6;
	NSString* myNewString = [NSString stringWithFormat:@"%f", currentNumber];
	textField1.text= myNewString;*/
}
-(IBAction) b7:(id)sender
{
	myString=[myString stringByAppendingString:@"7"];
	textField1.text=myString;
	/*currentNumber=currentNumber * 10 + 7;
	NSString* myNewString = [NSString stringWithFormat:@"%f", currentNumber];
	textField1.text= myNewString;*/
}
-(IBAction) b8:(id)sender
{
	myString=[myString stringByAppendingString:@"8"];
	textField1.text=myString;
	/*currentNumber=currentNumber * 10 + 8;
	NSString* myNewString = [NSString stringWithFormat:@"%f", currentNumber];
	textField1.text= myNewString;*/
}
-(IBAction) b9:(id)sender
{
	myString=[myString stringByAppendingString:@"9"];
	textField1.text=myString;
	/*currentNumber=currentNumber * 10 + 9;
	NSString* myNewString = [NSString stringWithFormat:@"%f", currentNumber];
	textField1.text= myNewString;*/
}
-(IBAction) plus:(id)sender
{
	operator=1;
	first=[textField1.text intValue];
	myString=@"";
}
-(IBAction) minus:(id)sender
{
	operator=2;
	first=[textField1.text intValue];
	myString=@"";
}
-(IBAction) multiply:(id)sender
{
	operator=3;
	first=[textField1.text intValue];
	myString=@"";
}
-(IBAction) divide:(id)sender
{
	operator=4;
	first=[textField1.text intValue];
	myString=@"";
}

switch (operator) {
		case 1:
		{
			first;
			break;
		}
		default:
			first;
}
/*
if (operator == 1)
{
	second=[textField1.text, intValue];
	first=first+second;
	textField1.text=first;
}*/




// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
	myString = @"";
}


- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}

- (void)dealloc {
    [super dealloc];
}
@end
Posted
Comments
Guyverthree 12-Jul-11 11:17am    
I'm not 100% sure which is why this is not an answer, I believe that you cannot define code without it being inside a function definition.
Nagy Vilmos 12-Jul-11 12:33pm    
Correct, add this as the answer
shwetha_m6 20-Jul-11 10:54am    
Thanks SafarTimura yes you were right its working fine now. :) I really appreciate your help.
shwetha_m6 20-Jul-11 10:54am    
Thanks SafarTimura yes you were right its working fine now. :) I really appreciate your help.

1 solution

C#
switch (operator) {
        case 1:
        {
            first;
            break;
        }
        default:
            first;
}


this needs to be inside a function block, this is why this code is failing to be built.
 
Share this answer
 
Comments
Albert Holguin 13-Jul-11 11:20am    
I assumed he omitted the method block, but if since he never responded to you... I'll assume you're correct, my 5...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900