Dice Game

I made a dice game, it works fine, but I want to change something.

I want to output something like:
"Player 1 do you want to throw the dice?" and then generate the random number. Instead my program keeps on generating random numbers by itself.
And the same for player 2, only when I play vs Computer, the Computer should generate the number by itself (which is already doing).

Hope that I was clear enough, if not feel free to ask additional questions. Thank you.

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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#include <iostream>
#include <conio.h>
#include "ctime"
#include <Windows.h>
using namespace std;

void HumanVsHuman();
void HumanVsComputer();

int main()
{
	cout<<endl;
	cout<<"\t\tWelcome to the Dices Game!" << endl<<endl<<endl;

	cout << "\t   .........                           "<<endl;
	cout << "\t   :~, *   * ~,                        "<<endl;
	cout << "\t   : ~, *   * ~.                       "<<endl;
	cout << "\t   :  ~........~                       "<<endl;
	cout << "\t   : *:         :      ~'~,            "<<endl;
	cout << "\t   :  :         :    ~' *  ~,          "<<endl;
	cout << "\t   ~* :    *    : ,~' *    * ~,        "<<endl;
	cout << "\t    ~,:         :.~,*    *  ,~ :       "<<endl;
	cout << "\t     ~:.........::  ~, *  ,~   :       "<<endl; 
	cout << "\t                 : *  ~,,~  *  :       "<<endl;
	cout << "\t                 :* * * :  *   :       "<<endl;
	cout << "\t                  ~, *  : *  ,~        "<<endl;
	cout << "\t                    ~,  :  ,~          "<<endl;
	cout << "\t                      ~,:,~            "<<endl;
	cout<<endl<<endl;
	cout<<"\t1 - Human vs Human" << endl;
	cout<<"\t2 - Human vs Computer"<< endl;
	cout<<"\t3 - Exit Game" << endl<<endl;

	int choice;

	while(cin)
	{
		cin>>choice;
		{
			switch(choice)
			{
			case 1:
				HumanVsHuman();
				break;
			case 2:
				HumanVsComputer();
				break;
			case 3:
				return 0;
			}
		}
	}
	_getch();
}

void HumanVsHuman()
{
	int player1=100; //player 1 money
	int player2=100; //player 2 money
	int i, a1, a2, b1, b2;

	do
	{					
		srand(time(0));
		for(i=0; i<100; i+=2)
		{
			a1 = rand() % 6 + 1;
		}

		for(i=0; i<100; i+=2)
		{
			a2 = rand() % 6 + 1;
		}

		srand(time(0));
		for(i=0; i<100; i++)
		{
			b1 = rand() % 6 + 1;
		}

		for(i=0; i<100; i++)
		{
			b2 = rand() % 6 + 1;
		}
		
		Sleep(1500);
		cout << "\nPlayer 1: You roll the the 2 dices: " <<a1<<" "<<a2<<endl;
		Sleep(1500);
		cout << "Player 2: You roll the 2 dices: " <<b1<<" "<<b2<<endl;

    if(a1+a2 == b1+b2)
	{
		cout<<"It's a draw. Keep playing...";
		cout << "Player's 1 money: " << player1 <<"$" << endl;
		cout << "Player's 2 money: " << player2 <<"$" << endl;
	}

	if(a1+a2 > b1+b2)
	{
		cout << "Player 1 has won!\n";	
		player1 = player1 + 10;
		player2 = player2 - 10;

		cout << "Player's 1 money: " << player1 <<"$" << endl;
		cout << "Player's 2 money: " << player2 <<"$" << endl;
	}

	if(b1+b2 > a1+a2)
	{
		cout << "Player 2 has won!\n";
		player2 = player2 + 10;
		player1 = player1 - 10;

		cout << "Player's 1 money: " << player1 <<"$" << endl;
		cout << "Player's 2 money: " << player2 <<"$" << endl;

	}

	} while (player1 != 0 && player2 != 0);

	if(player1 == 0) cout<<"Player1 loses!"; 
	if(player2 == 0) cout<<"Player2 loses!"; 
}

void HumanVsComputer()
{
	int i, a, b;
	do
	{
		srand(time(0));
		for(i=0; i<100; i+=2)
		{
			a = rand() % 6 + 1;
		}

		srand(time(0));
		for(i=0; i<100; i++)
		{
			b = rand() % 6 + 1;
		}

		Sleep(1500);
		cout << "Player 1: You roll the dice: " <<a<<endl;
		Sleep(1500);
		cout << "Computer: You roll the dice: " <<b<<endl;

	} while(a==b);

	if(a>b)
	{
		cout << "Player 1 has won!";
	}

	if(b>a)
	{
		cout << "Computer has won!";
	}
}
Then you just need to modify the loop, why don't you allow them to change the bet, instead of just Y/N?
Thanks for that idea, it's much better.
Topic archived. No new replies allowed.