Am getting this problem which I have commented in my main file:
#import <Foundation/Foundation.h>
#import "Person.h"
int main (int argc, const char * argv[])
{
// Create an instance of Person
Person *person = [[Person alloc]init];
// Give the instance variables interesting values
[person setWeightInKilos:96];
[person setHeightInMeters:1.8];
// Call the body mass index
float bmi = [person bodyMassIndex];
NSLog(@"person has a bmi of %f", bmi);
}
return 0; // Expected identifier or '('
} // Expected external declaration
Person.h
#import <Foundation/Foundation.h>
@interface Person : NSObject {
float heightInMeters;
int weightInKilos;
}
// You will be able to set those instance variables using these methods
- (void)setHeightInMeters:(float)h;
- (void)setWeightInKilos:(int)w;
// This method calculates the body weight index
- (float)bodyMassIndex;
@end
Person.m
#import "Person.h"
@implementation Person
- (void)setHeightInMeters:(float)h{
heightInMeters = h;
}
- (void)setWeightInKilos:(int)w {
weightInKilos = w;
}
- (float)bodyMassIndex {
return weightInKilos / (heightInMeters * heightInMeters);
}
@end
You have a stray
}in your program before thereturn 0;. The error is rather misleading. You may want to switch over to using LLVM instead of GCC (this will get you faster compilation too, not just better errors).