I've been stuck. pls help me to continue.

Create a program that implements the following game:


This game has 4 players. There is a banker and three other players. The banker rolls a pair of dice. Each of the player guesses the sum of the result. The banker has an initial capital of PhP 100,000.00. The players each has PhP 20,000.00. Every time a player guesses the resulting sum, a corresponding bet is placed. If the player guesses the right sum, the banker pays him/her with an amount equivalent to his/her bet. The money of the banker and the player must be updated. The game must terminate if the banker's money has dwindled down to PhP 10,000.00. If should also stop if the only one player is playing against the banker. You have to ask the player if he/she wants to continue the game or not. A player must stop playing if his/her money has dwindled down to PhP 100.00. Checks must be made by the program. A player cannot bet an amount that cannot be covered by his current money. If the total sum of the bets from the players exceeds the capital of the banker the players must re-enter bets.




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
#include <iostream.h>
#include <time.h>
#include <stdlib.h>


void main (){

    int sum;
    srand((unsigned)time(NULL));
    int die1 = rand()%6 + 1;
    bool p1 = true, p2 = true, p3 = true;
/*    for(int i=0; i<20000; i++)
        for(int j=0; j<20000; j++);

    srand((unsigned)time(NULL));*/
    int die2 = rand()%6 + 1;
    
    
    sum = die1+die2;

    
    int player1=20000,player2=20000,player3=20000,banker=100000;
    int guess1, guess2, guess3;
    int bet1, bet2, bet3;
	int play;
	int money=100;


    cout<<"Enter your guess, player1"<<endl;
    cin>>guess1;
    cout<<"Enter your bet"<<endl;
    cin>>bet1;

		
    if (guess1==sum){
        cout<<"Congrats!you win"<<endl;
        player1= player1 + bet1;
    }
    else{
        cout<<"you loose"<<endl;
        player1 = player1-bet1;
        banker = banker + bet1;
    }
	

    cout<<"Enter your guess, player2"<<endl;
    cin>>guess2;
    cout<<"Enter your bet"<<endl;
    cin>>bet2;

    if (guess2==sum){
        cout<<"Congrats!you win"<<endl;
        player2 = player2 + bet2;
    }
    else{
        cout<<"you loose"<<endl;
        player2 = player2 - bet2;
        banker = banker + bet2;
    }


    cout<<"Enter your guess,player3"<<endl;
    cin>>guess3;
    cout<<"Enter your bet"<<endl;
    cin>>bet3;

    if (guess3==sum){
        cout<<"Congrats!you win"<<endl;
        player3 = player3 + bet3;
    }
    else
	{
        cout<<"you loose"<<endl;
        player3 = player3 - bet3;
        banker = banker + bet3;
    }

	cout<<"The sum of dice is"<<" "<<sum<<endl<<endl;

	cout<<"The current account of player1 is"<<" "<<player1<<endl;
	cout<<"The current account of player2 is"<<" "<<player2<<endl;
	cout<<"The current account of player3 is"<<" "<<player3<<endl;
    cout<<"The current account of banker is" <<" "<<banker<<endl<<endl;

	

	cout<<"Player1 do you want to play again?(1 for yes and 2 for not)"<<endl;
	cin>>play;


	if(play==1)
	{
		cout<<"Goodluck for the next game"<<endl;
		cout<<"You have a money of"<<player1<<endl;


	}
	else
	{
		cout<<"Thanks for playing";
		cout<<"You have a money of"<<player1<<endl;
		
	}



	cout<<"Player2 do you want to play again?(1 for yes and 2 for not)"<<endl;
	cin>>play;


	if(play==1)
	{
		cout<<"Goodluck for the next game"<<endl;
		cout<<"You have a money of"<<player2<<endl;
	}
	else 
	{
		cout<<"Thanks for playing"<<endl;
		cout<<"You have a money of"<<player2<<endl;
	}



	cout<<"Player3 do you want to play again?(1 for yes and 2 for not)"<<endl;
	cin>>play;

	
	if(play==1)
	{
		cout<<"Goodluck for the next game"<<endl;
		cout<<"You have a money of"<<player3<<endl;
	}
	else
	{
		cout<<"Thanks for playing"<<endl;
		cout<<"You have a money of"<<player3<<endl;
	}

	
}
	
	
pls help me to continue the code, the player must choose whether to continue or not, if yes so the game must continue until he/she dont want to play anymore or his money will be 100 he must be disqualified in the game..
Hi - This should probably be on the 'Beginers' board, rather than 'Articles', but as there's no way to move or delete I guess it'll have to stay here.

The next thing I would do would be to tidy up the code by moving common sections into functions.
EG
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
int PlayAgain(int playerNumber, int cash)
{
    int play;
    cout<<"Player " << PlayerNumber << " do you want to play again?(1 for yes and 2 for not)"<<endl;
    cin>>play;

    if(play==1)
    {
        cout<<"Goodluck for the next game"<<endl;
    }
    else
    {
        cout<<"Thanks for playing"<<endl;
    }
    cout<<"You have a money of "<<cash<<endl;
    return play;
}

Once you have done that you would end up with something along the lines of
1
2
3
4
5
6
7
8
9
10
11
12
13
14
//Global Variables here
//Function headers here
void main()
{
    //Main Variables here  
    RollDice();    //call function for banker to roll dice
    Guess(1,player1);  //call function for player 1 to guess and bet
    Guess(2,player2);
    Guess(3,player3);
    PlayAgain(1,player1);   //call function for player 1 to continue or quit
    PlayAgain(2,player3);
    PlayAgain(3,player3);
}
//function definitions here 

You should then look at changing the player cash totals to an array of integers so you could use a 'For' loop to do the three guess and 3 continue calls.
You would then use a 'while' loop to have the roll & guess sequence repeat until the end conditions occured.
closed account (z05DSL3A)
Faldrax wrote:
|Hi - This should probably be on the 'Beginers' board, rather than 'Articles', but as there's no way to move
| or delete I guess it'll have to stay here.

The admins tend to delete posts that should not be here, so don't be surprised if this thread disappears in the next day or two.
Last edited on
Topic archived. No new replies allowed.