3737using namespace std ;
3838
3939const int NUM_DICES_FOR_USER = 3 ;
40+ const int NUM_TOTAL_DICE = NUM_DICES_FOR_USER * 2 ;
4041const short int RED_WIN = 1 ;
4142const short int BLUE_WIN = -1 ;
4243const unsigned short int FACES_DICES = 6 ;
@@ -52,19 +53,23 @@ int main() {
5253 srand (seed);
5354
5455 unsigned int * dices = generateDicesNumber ();
55-
56+
5657 sort (dices, dices+NUM_DICES_FOR_USER);
5758 sort (dices+NUM_DICES_FOR_USER, dices+(NUM_DICES_FOR_USER*2 ));
58-
59+
5960 showDices (dices);
6061 compareValue (dices);
6162
6263 free (dices);
64+ return EXIT_SUCCESS;
6365}
6466
6567unsigned int * generateDicesNumber (){
66- unsigned int * dices = new unsigned int ;
67- for (int i = 0 ; i < NUM_DICES_FOR_USER*2 ; i++) dices[i] = rand () % FACES_DICES + 1 ;
68+ unsigned int * dices = new unsigned int [NUM_TOTAL_DICE];
69+
70+ for (int i = 0 ; i < NUM_TOTAL_DICE; i++)
71+ dices[i] = rand () % FACES_DICES + 1 ;
72+
6873 return dices;
6974}
7075
@@ -73,16 +78,22 @@ void compareValue(unsigned int * dices) {
7378
7479 for (int i = NUM_DICES_FOR_USER-1 ; i >= 0 ; i--) {
7580 cout << endl << " N " << dices[i] << " vs " << dices[i+NUM_DICES_FOR_USER];
76- if (dices[i] > dices[i+NUM_DICES_FOR_USER]) cout << " => RED WIN" ;
77- else cout << " => BLUE WIN" ;
81+
82+ if (dices[i] > dices[i+NUM_DICES_FOR_USER])
83+ cout << " => RED WIN" ;
84+ else
85+ cout << " => BLUE WIN" ;
7886 }
7987 cout << endl;
8088}
8189
8290void showDices (unsigned int * dices){
8391 cout << " \n Blue dices: " << endl;
84- for (int i = NUM_DICES_FOR_USER*2 -1 ; i >= 0 ; i--) {
85- if (i == 2 ) cout << " \n\n Red dices: " << endl;
92+
93+ for (int i = NUM_TOTAL_DICE-1 ; i >= 0 ; i--) {
94+ if (i == 2 )
95+ cout << " \n\n Red dices: " << endl;
96+
8697 cout << dices[i] << endl;
8798 }
8899}
0 commit comments