forked from Light-City/CPlusPlusThings
-
Notifications
You must be signed in to change notification settings - Fork 0
/
掷骰子.cpp
63 lines (61 loc) · 1.01 KB
/
掷骰子.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include<iostream>
#include<cstdlib>
using namespace std;
int rolldice();
int main(int argc, char const *argv[])
{
int flag;
unsigned seed;
cout<<"ÇëÊäÈëÎÞ·ûºÅÕûÊý£º"<<endl;
cin>>seed;
srand(seed);
int sum = rolldice();
int selfdim;
switch(sum)
{
case 7:
case 11:
flag=1;
break;
case 2:
case 3:
case 12:
flag=2;
break;
default:
flag=0;
selfdim=sum;
break;
}
while(flag==0)
{
sum=rolldice();
if(sum==selfdim)
{
flag=1;
}
else if(sum==7)
{
flag=2;
}
}
if(flag==1)
{
cout<<"player win\n";
}
else
{
cout<<"player loses\n";
}
system("pause");
return 0;
}
int rolldice()
{
int sum=0;
int dim1 = rand()%6+1;
int dim2 = rand()%6+1;
sum = dim1+dim2;
cout<<"sum="<<dim1<<"+"<<dim2<<endl;
return sum;
}