#include <iostream>
#include<string>
#include<iomanip>
#include<conio.h>
usingnamespace 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;
}
elseif ((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;
}
elseif ((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;
}
elseif (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");
}
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.