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
|
#include <iostream>
#include <cstdlib>
using namespace std;
int main(){
int outcome (int,int);
int newDieValue(int & ,int & );
int die1,die2;
int win =0 ,lost =0, draw= 0; //my counter
for (int i=0 ; i < 3 ; i++){ //start of for loop
cout << "\nPlease enter first die \n";
cin >> die1;
cout << "Please enter second die\n";
cin >> die2;
//check if numbers entered are valid
/*****************************************************************/
while ((die1 < 1 || die1 > 6) || (die2 < 1 || die2 > 6) )
{
cout << "\nInvalid die , Please reenter a number from 1-6\n";
cout << "\nPlease enter first die \n";
cin >> die1;
cout << "Please enter second die\n";
cin >> die2;
}
/******************************************************************/
cout <<"\nDie one is : "<< die1 << endl << "Die two is : "<< die2 <<endl; //Prints result of dice
cout << outcome (die1, die2)<<endl;
//keeps stats of wins lost and draw
if (outcome(die1,die2) == 1)
win++;
else if (outcome(die1,die2) == -1)
lost++;
else if(outcome(die1,die2) ==0)
draw++;
else;
//uses function to get new die value
newDieValue( die1, die2);
cout <<"\nDie one is : "<<die1 <<endl << " Die two is : "<<die2<<endl;
cout << outcome(die1,die2);
}//end of for loop
cout << "\n You won : "<< win << endl;
cout << " You lost :"<< lost <<endl;
cout << "You draw : "<< draw <<endl;
return 0;
}
/**********************************************/
//Function to calculate new value
int newDieValue(int &die1,int &die2){
die1=die1 + 2;
if (die1 > 6 ){
die1 = die1 -6;
return die1;
}
die2= die2 + 3;
if (die2 > 6 ){
die2 = die2 - 6;
return die2;
}
}
/************************************************************/
//Check to see if you win lose or draw
int outcome (int die1,int die2){
int total = die1 + die2;
const int win = 1, lose = -1 , draw = 0;
if (total == 7){
cout << " you win\n";
return win;
}
else if (total == 5){
cout << " you win\n";
return win;
}
else if (total == 12){
cout << " you win\n";
return win;
}
else if (total == 2){
cout << " you lose\n";
return lose;
}
else if (total == 4){
cout << " you lose\n";
return lose;
}
else if (total == 11){
cout << " you lose\n";
return lose;
}
else {
cout << " you draw\n";
return draw;
}
}//end of function
|