我也就一周听老师白话两节课,平时都没写过啊,555,网上看到的都是c程序啊,哪位有个c++的特别的发上来啊,同学都在图书馆找,我怕抄重了咧.
对了,这么长的代码到编译器里能不能复制粘贴啥的啊,一行一行打得打到啥时候啊,郁闷死了.啥都不懂咧
#include<iostream> #include<cstdlib>
using namespace std;
void displaymenu(); int getselection(); int game();
int main() { int selection=0; while(selection!=3) { //显示菜单 displaymenu();
//获取菜单选项 selection=getselection();
//选择匹配处理 switch(selection) { case 1: cout<<" 作者:程乐仙"<<endl; cout<<endl; break; case 2: cout<<game()<<endl; break; case 3: cout<<"quitting"<<endl; break; default: cout<<" \a麻烦你看清楚好吗?选择1 2 3!别胡弄"<<endl; cout<<endl; break; } }
return 0; }
//显示菜单 void displaymenu() { cout<<" 欢迎进入我的小制作"<<endl; cout<<endl; cout<<" ----------------------菜 单--------------------"<<endl; cout<<" 1=作者"<<endl; cout<<" 2=游戏"<<endl; cout<<" 3=退出"<<endl; cout<<endl; }
//游戏 int game() { char ans; //在用户完成之前一直循环 do { //选择一个密码 int fav=rand()%32;
//在用户猜中密码之前一只循环 int num; do { cout<<"guese my secret number(0-32)"; cin>>num;
//报告猜测情况 cout<<(num<fav?"too low":num>fav?"too hight":"right")<<endl; } while(num!=fav);
cout<<"go again?(y/n)"; cin>>ans; } while(ans=='y');
return 0; }
//从磁盘读取菜单选项 int getselection() { int selection; cout<<"做的不好,别见怪"<<endl; cin>>selection; return selection; }