小游戏-本人第一次编程序,多多指教
#include <iostream.h>#include <time.h>//time
#include <stdlib.h>//srand
void main()
{
cout<<"********************************************************************************";
cout<<"这是一个猜豆子的游戏,有一颗豆子,随机在1,2,3三个碗下面,请猜这个豆子在哪个碗下面。你一开始有20块钱,猜对一次得3块,猜错一次输3块"<<endl;
cout<<"********************************************************************************";
////////////////////////////////////////
srand((int)time(0));
int douzi=rand()%3;
int shuzi;
char answer;
int money;
do//1
{
char ready;
/////////////////
do//3
{
cout<<"准备好了么?(Y/N)";
cin>>ready;
if(ready=='N'||ready=='n')
{cout<<"我靠,你太慢了吧!"<<endl;}
else if(ready=='Y'||ready=='y')
{cout<<"开始游戏!"<<endl;}
else
{cout<<"请重新输入(Y/N)!"<<endl;}
cout<<endl;
}
while(ready!='Y'&&ready!='y');//3
///////////////
money = 20;
do//2
{
/////////////////////////////////////
//////////////////////////////////////
do//3
{
cout<<"请输入数字:< 1,2,3里面选一个 >:";
cin>>shuzi;
if(shuzi!=1&&shuzi!=2&&shuzi!=3)
{cout<<"Error!"<<endl;}
}
while(shuzi!=1&&shuzi!=2&&shuzi!=3);//3
///////////////////////////////////////////
/////
if(shuzi==douzi)
{
cout<<"狗屎运太好了!给你一颗糖吃吧"<<endl;
money=money+3;
cout<<"你现在还有 "<<money<<" 块"<<endl<<endl;
}
else
{
cout<<"哎,运气不好啊,你亏了3块大洋,哈哈";
money=money-3;
cout<<"你现在还有 "<<money<<" 块"<<endl<<endl;
}
/////
// cout<<endl<<money;
////
if(money<0)
{
cout<<"你破产了,哈哈!"<<endl;
}
else
{
cout<<"还要再来一次吗?(Y/N)";
cin>>answer;
if(answer=='N'||answer=='n')
cout<<"Bye Bye"<<endl;
else if(answer!='Y'&&answer!='y'&&answer!='N'&&answer!='n')
{
do//输入非法值(非Y,N,y,n)
{
cout<<"请重新输入!"<<endl;
cin>>answer;
}
while(answer!='Y'&&answer!='y'&&answer!='N'&&answer!='n');
};
}
/////
}
while(money>0&&answer!='N'&&answer!='n');//2
}
while(answer!='N'&&answer!='n'&&money>0);//1
////////////////////////////////////////
}