好的,所以我对目标 C 是全新的,为了给自己一点练习,我做了一个小程序。这些程序假设计算出你有多少天。我有这个我无法弄清楚的错误。继承人的代码:
年龄.h
#import <Foundation/Foundation.h>
@interface Age : NSObject {
int age;
int age365;
int lyear;
}
-(void) howOld;
@end
年龄.m
#import "Age.h"
@implementation Age
-(void) howOld{
NSLog(@"How old are you currently?\n");
scanf("age");
NSLog(@"You entered %i", age);
}
@end
月.h
#import "Age.h"
@interface Month : Age{
int month;
}
-(void) whatMonth;
@end
月.m
#import "Month.h"
@implementation Month
-(void) whatMonth{
NSLog(@"What month is it? (Number)\n");
scanf("month");
NSLog(@"you entered %i", month);
}
@end
天.h
#import "Month.h"
@interface Day : Month{
int day;
}
-(void) whatDay;
-(void) printAge;
@end
天.m
#import "Day.h"
@implementation Day
-(void) whatDay{
NSLog(@"What day is it? (Number)");
scanf("day");
NSLog(@"You entered %i", day);
day = month*30+day+age365;
}
-(void) printAge{
age365 = age * 365;
lyear = age/4;
age = lyear + age365;
NSLog(@"You are %i days old", day);
}
@end
主程序
#import <Foundation/Foundation.h>
#import "Age.h"
#import "Month.h"
#import "Day.h"
int main(int argc, const char * argv[])
{
@autoreleasepool {
Age *a = [[Age alloc]init];
[a howOld];
Month *m = [[Month alloc]init];
[m whatMonth];
Day *d = [[Day alloc]init];
[d whatDay];
[d printAge];
}
return 0;
}
输出 *这是错误*
**Lets me type**(
2013-08-08 17:27:26.121 HMDAI[10989:303] How old are you currently?
3)
**Does by itself**(
2013-08-08 17:27:43.854 HMDAI[10989:303] You entered 0
2013-08-08 17:27:43.854 HMDAI[10989:303] What month is it? (Number)
2013-08-08 17:27:43.855 HMDAI[10989:303] you entered 0
2013-08-08 17:27:43.855 HMDAI[10989:303] What day is it? (Number)
2013-08-08 17:27:43.855 HMDAI[10989:303] You entered 0
2013-08-08 17:27:43.856 HMDAI[10989:303] You are 0 days old
)
我做错了什么?如果有帮助,我会使用 XCode。