#import <Foundation/Foundation.h>
int main(
int argc,
const
char * argv[])
{
@autoreleasepool
{
int randomNumber=
1;
int userGuess =
1;
BOOL continueGussing=
TRUE;
BOOL keepPlaying=
TRUE;
char yesNo=
' ';
while (keepPlaying)
{
randomNumber=(arc4random()%
101);
NSLog(
@" 我们来玩个游戏,猜猜随机数字吧
",randomNumber);
while (continueGussing)
{
NSLog(@"
选择一个0
到100
之间的数字,祝你好运
"
);
scanf(
"%i",&userGuess);
fgetc(stdin);
if (userGuess==randomNumber)
{
continueGussing=
FALSE;
NSLog(
@" 我擦,猜对了!
");
}
else
if (userGuess>randomNumber)
{
NSLog(
@" 高了
");
}
else
{
NSLog(
@" 低了
");
}
NSLog(
@" 你猜的是
%d",userGuess);
}
NSLog(
@" 还敢玩么,憨比?
y or n ");
yesNo=fgetc(stdin);
if(yesNo==
'y'||yesNo==
'Y')
{
keepPlaying=
TRUE;
}
continueGussing=
FALSE;
}
}
return
0;
}