标签:tom can == 数字游戏 猜数字 ret pre init interface
// // main.m // 猜数 // #import <Foundation/Foundation.h> #import "Guess.h" int main(int argc, const char * argv[]) { Guess * number = [[Guess alloc]init]; NSLog(@"请输入您所猜的数字"); int guessNumber; scanf("%d",&guessNumber); [number guessNumber:guessNumber]; //NSLog(@"%d",number->_guessNumber); return 0; }
#import <Foundation/Foundation.h> @interface Guess : NSObject { @public int _guessNumber; } -(void)guessNumber:(int)number; @end
#import "Guess.h" @implementation Guess -(id)init { self = [super init]; if (self != nil) { _guessNumber = 100; } return self; } -(void)guessNumber:(int)number { //NSLog(@"请输入您所猜的数字"); if(number==_guessNumber) { NSLog(@"您猜对了"); } else if(number > _guessNumber) { NSLog(@"您猜的大了"); } else { NSLog(@"您猜的小了"); } } @end
标签:tom can == 数字游戏 猜数字 ret pre init interface
原文地址:http://www.cnblogs.com/wzjhoutai/p/6795390.html