| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 654 人关注过本帖
标题:菜鸟编的,猜数字游戏-单纯版.
取消只看楼主 加入收藏
wfpb
Rank: 6Rank: 6
等 级:贵宾
威 望:29
帖 子:2188
专家分:0
注 册:2006-4-2
收藏
 问题点数:0 回复次数:0 
菜鸟编的,猜数字游戏-单纯版.

#include<iostream>
#include<cstdlib>
using namespace std;

int menu();
void play();

int main()
{
int choice,operate,magic;
do
{
operate=menu();
switch (operate)
{
case 1:play();break;
case 2:break;
case 3:cout<<"Goodbye!"<<endl;break;
}
}while (operate != 3);

return 0;
}


// menu fuction...
int menu()
{
int choice;
cout<<"1.Get a new magic number."<<endl;
cout<<"2.Play now."<<endl;
cout<<"3.Quit."<<endl;
cout<<"Enter your choice:";
cin>>choice;
return choice;
}

//play fuction...
void play()
{
int i,magic,guess;
magic = rand();
magic = magic%10;
for (i=1;i<=3;i++)
{
cout<<"Guess :";
cin>>guess;
if (guess==magic)
{cout<<"**RIGHT**"<<endl<<endl<<endl;break;}
else if (guess>magic)
cout<<"It's too high."<<endl;
else cout<<"It's too low."<<endl;
}
if (i==4)
{cout<<endl<<"**Your chance have losted out.**"<<endl<<"End game this time.";
cout<<endl<<"The magicNum is "<<magic;
cout<<endl<<"Come on again?"<<endl<<endl<<endl;}

}

搜索更多相关主题的帖子: int 数字 游戏 menu 
2006-04-09 16:23
快速回复:菜鸟编的,猜数字游戏-单纯版.
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.031818 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved