掷骰子问题
#include
#include
using namespace std;
int Great();
int n1=0,n2=0;
int main()
{
char c='Y';
while(c=='Y')
{
Great();
cout<<"是否想继续进行游戏??? Y or N :";cin>>c;
system("cls");
}
cout<<"游戏者赢得次数:"<<n1<<endl;
cout<<"游戏者失败的次数:"<<n2<<endl;
return 0;
}
int Great()
{
int num1,num2,sum=0;
num1=rand()%7;
num2=rand()%7;
cout<<num1<<" "<<num2<<endl;
sum=num1+num2;
cout<<sum<<endl;
if(sum==7||sum==11)
{
n1++;
cout<<"游戏者获胜!!!"<<endl;
}
else if(sum==2||sum==3||sum==12)
{
n2++;
cout<<"游戏者失败!!!"<<endl;
}
else
while(1)
{
num1=rand()%7;
num2=rand()%7;
cout<<num1<<" "<<num2<<endl;
cout<<sum<<endl;
if(sum==num1+num2)
{
n1++;
cout<<"游戏者获胜!!!"<<endl;
break;
}
else if(num1+num2==7)
{
n2++;
cout<<"游戏者失败!!!"<<endl;
break;
}
}
return sum;
}