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
64
65
66
67
68
69
#include <cstdlib>
#include <iostream>
#include <ctime>
#include<stdio.h>

using namespace std;

int main(int argc, char **argv){
int a,b,c;; //骰子
int p_mon=1000,p_bet=0,p_siz;//玩家的資本,押注,押的大小
int e_win=0,e_los=0 ; //贏幾次,輸幾次
char ch;//迴圈

srand(time(0));

cout << "\t歡迎來到義守應數賭博樂園 ● 以下開始為您介紹遊戲玩法"<<endl;
cout << "\t首先,您的賭本為1000元,\n";
cout << "\t總共三個骰子,猜猜看是大(B)還是小(S)\n";
cout << "\t【大】為三個骰子總合大於11;【小】為三個骰子總合小於10\n";

do{
a = rand() % 6 + 1;
b = rand() % 6 + 1;
c = rand() % 6 + 1;
do{
cin.clear();
cin.sync();
cout << "您現有『"<<p_mon<<"』元,請輸入要押注的金額\n" ;
cin >> p_bet;
if(cin.fail())
cout << "\n請輸入正確數字\n";
else if( p_bet <= 0 )
cout << "無押注就無遊戲(╯‵□′) ╯ 請重新押注或滾蛋\n" ;
else if( p_bet > p_mon )
cout << "你不是郭台銘 沒這麼多錢╮(╯_╰)╭ 請押注正確金額\n " ;
}while(p_bet <= 0 || p_bet > p_mon || cin.fail());

cout <<"您押注【" << p_bet << " 】元後剩下【"<< p_mon-p_bet << "】元\n";
cout << "現在就來猜猜是(B)ig或(S)mall還是您要(E)xit呢?\n" ;
do{
ch = getchar();
}while(!(ch == 'B' || ch == 'S' || ch == 'E'));
if ( ch == 'E' )
{
printf("骰子為 %d + %d + %d = %d\n",a, b, c, a+b+c);
if ( (a+b+c >= 11 && ch == 'B')||(a+b+c<=10 && ch == 'S') ) {
e_win++;
p_mon += p_bet;
cout << "恭喜中獎,贏到了【"<<p_bet<<"】~ 您的總賭本尚有【" <<p_mon<<"】元!\n";
}else{
e_los++;
p_mon-=p_bet;
if ( a+b+c >= 11 )
ch = 'B';
else
ch = 'S';
cout << "是【"<<ch<<"】喔! 恭喜莊家贏了【"<<p_bet<< "】。現在您剩【" <<p_mon<<"】元\n";

}
cout<<"再玩一次嗎 ??? (Y)\n";
cin>>ch;
printf("\n");
}while(ch=='y'||ch=='Y');// 輸入y就會再玩一次

cout << "您今日贏了"<< e_win << "次,輸了" << e_los <<"次。" << endl ;
cout << "今日累積獎金為" << p_mon << " 元,歡迎下次再度光臨" << endl ;
system("PAUSE");
return 0;
}