一个非常简单的C++游戏代码。

# include & ltiostream & gt

# include & ltcmath & gt

# include & ltstdlib.h & gt

使用命名空间std

int main()

{

int num

int猜;

再次充电;

num = rand()% 100;

cout & lt& lt“一个0-100的数字。你能猜到会是什么吗?”& lt& ltendl

做{

cout & lt& lt"请输入一个数字:"

CIN & gt;& gt猜测;

if (num==guess)

{

cout & lt& lt“哇,你猜对了,真聪明!!"& lt& ltendl

退出(0);

}

else if(num & lt;猜测){

cout & lt& lt“哇,猜大的,换个小一点的!!"& lt& ltendl

}

else if(num & gt;猜测){

cout & lt& lt“哇,猜小了,换个大点的!!"& lt& ltendl

}

cout & lt& lt“想继续猜吗?(是/否)";

CIN & gt;& gt再次;

} while(again = = ' Y ' | | again = = ' Y ');

系统(“暂停”);

返回0;

}