Help with if statement... i think

Could someone help me figure out where i went wrong? Im assuming its my if statements from the way it its running after compile.
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
  #include <iostream>
#include<string>
#include<iomanip>
#include<conio.h>

using namespace std;

int Player1Dice1;// declare player 1 first dice
int Player1Dice2;//declare player 1 second dice
int Player1Sum;//declare player 1 sum of both dice
int Player1Wins;// declare Player 1 number of wins
int Player2Dice1;//declare player 2 first dice
int Player2Dice2;//declare player 2 second dice
int Player2Sum;//declare player 2 sum of both dice
int Player2Wins;//declare Player 2 number of wins
int Round = 1;


int main(){
	
	cout << "Welcome to a  Dice game simulator" << endl << endl;


	while (Round >=0 && Round <=10) //while loop to keep game running for 10 rounds
	{
		cout << "**************** ROUND" << Round << " ****************" << endl;
		cout << "Player 1 press any key to roll dice" << endl << endl;
		system("PAUSE");//Waits for user button input to continue

		Player1Dice1 = (rand() % 6 + 1);// first random dice roll
		return Player1Dice1;
		Player1Dice2 = (rand() % 6 + 1);// second random dice roll
		return Player1Dice2;

		Player1Sum = Player1Dice1 + Player1Dice2; // sum of player ones dice rolls
		return Player1Sum;
		
		cout << "Player 1 rolled " << Player1Dice1 << " & a " << Player1Dice2 << endl;


		if (Player1Dice1 = Player1Dice2)
		{
			cout << "PLAYER 1 ROLLED DOUBLE. PLAYER 1 WINS!!!" << endl;
			Player1Wins = Player1Wins + 1;
		}
		else if ((Player1Dice1 = 1) && (Player1Dice2 = 1))// SNAKE EYES IF STATEMENT IF DICE BOTH 1 
		{
			cout << "SNAKE EYES!!! PLAYER 1 HAS LOST ! " << endl;
			Player2Wins = Player2Wins + 1;
		}

		//pLAYER 2 TURN
		else{
			cout << "Player 2 press any key to roll dice" << endl << endl;
			system("PAUSE");//Waits for user button input to continue

			Player2Dice1 = (rand() % 6 + 1);// first random dice roll
			return Player2Dice1;
			Player2Dice2 = (rand() % 6 + 1);// second random dice roll
			return Player2Dice2;
			Player2Sum = Player2Dice1 + Player2Dice2; // sum of player 2 dice rolls
			return Player2Sum;

			cout << "Player 2 rolled " << Player2Dice1 << " & a " << Player2Dice2 << endl;
		}

		if (Player2Dice1 = Player2Dice2)
		{
			cout << "PLAYER 2 ROLLED DOUBLE. PLAYER 2 WINS!!!" << endl;
			Player2Wins = Player2Wins + 1;
		}
		else if ((Player2Dice1 = 1) && (Player2Dice2 = 1))//SNAKE EYES IF STATEMENT IF DICE BOTH 1 
		{
			cout << "SNAKE EYES!!! PLAYER 1 HAS LOST ! " << endl;
			Player1Wins = Player1Wins + 1;
		}
		
			Round = Round + 1;

		}// end of while loop


	                         //Display results and winner
	cout << "**********************************************" << endl;
	cout << "*                 RESULTS                    *" << endl;
	cout << "**********************************************" << endl;
	cout << "PLAYER 1 WON " << Player1Wins << "OUT OF 10 ROUNDS" << endl;
	cout << "PLAYER 2 WON " << Player2Wins << "OUT OF 10 ROUNDS" << endl;
	if (Player1Wins <= Player2Wins)//if player 1 has less wins then player 2 player one wins
	{
		cout << "  . . ." << endl;
		cout << " . o o ." << endl;
		cout << " . \_/ ." << endl;
		cout << "  . . ." << endl;
		cout << "PLAYER 2 WINS!!!!" << endl;
	}
	else if (Player1Wins >= Player2Wins)//if player 1 has more wins then player 1 wins
	{
		cout << "  . . ." << endl;
		cout << " . o o ." << endl;
		cout << " . \_/ ." << endl;
		cout << "  . . ." << endl;
		cout << "PLAYER 1 WINS!!!!" << endl;
	}


		
	cout << "The game has ended" << endl;
		cout << "Press any key to continue..." << endl;
		system("PAUSE");
	}
Last edited on
Line 31,33,36,58,60,62: return is going to cause your program to exit.

Line 41,46,67,72: = is the assignment operator. You want the comparison operator which is ==.

Line 89: If the number of wins are equal, you declare player 2 as the winner. You should be declaring a tie if they are equal.






Thanks for the reply.
I was under the impression that the return was needed to store the int into what i had declared. Not sure where I got that from. Took those out though. Thanks

Cant believe I Missed the second =. Thanks again.

As for line 89, I wanted it to be if player 1 wins is less than player 2 than player 2 wins.
<= isn't correct? I do need to add a statement in case of a tie though. Thanks for that also.

Last edited on
As for line 89, I wanted it to be if player 1 wins is less than player 2 than player 2 wins.
<= isn't correct?


Pretty sure that if you want to check if player 1's score is less than player 2's score you forget the =, and just use the <.
Thanks!
So I've fixed what was mentioned but am still having the same problem.

Something to do with my if statements i think.
How could I submit the output?

Both player 1 and 2 end up winning every round lol
Topic archived. No new replies allowed.