-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathmorra.cpp
87 lines (66 loc) · 2.23 KB
/
morra.cpp
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
//*****************************************************************************************************
// Morra Game Simulation
//
// This program is a simple game of Morra (a game played with fingers) between two players and
// the results of each game are written to a file.
//
//*****************************************************************************************************
#include <cstdlib>
#include <ctime>
#include <fstream>
#include <iostream>
using namespace std;
//*****************************************************************************************************
int main() {
const int MAX_FINGERS = 5.,
MIN_FINGERS = 1,
MAX_GUESS = 10,
MIN_GUESS = 0;
int playerOneFingers,
playerOneGuess,
playerTwoFingers,
playerTwoGuess,
sum;
ofstream out("result.txt");
short seed;
seed = time(0);
srand(seed);
playerOneFingers = rand() % (MAX_FINGERS - MIN_FINGERS) + MIN_FINGERS;
playerOneGuess = rand() % (MAX_GUESS - MIN_GUESS) + MIN_GUESS;
playerTwoFingers = rand() % (MAX_FINGERS - MIN_FINGERS) + MIN_FINGERS;
playerTwoGuess = rand() % (MAX_GUESS - MIN_GUESS) + MIN_GUESS;
out << "Fingers\tTotal" << endl;
out << playerOneFingers << "\t\t" << playerOneGuess << endl;
out << playerTwoFingers << "\t\t" << playerTwoGuess << endl;
sum = playerOneFingers + playerTwoFingers;
out << "\nCorrect total is " << sum << endl;
if (sum == playerOneGuess && sum == playerTwoGuess)
out << "TIE" << endl;
else if (sum == playerOneGuess)
out << "PLAYER 1 WINS" << endl;
else if (sum == playerTwoGuess)
out << "PLAYER 2 WINS" << endl;
else
out << "NO ONE WINS" << endl;
return 0;
}
//*****************************************************************************************************
/*
Fingers Total
4 5
3 9
Correct total is 7
NO ONE WINS
*****************************************************************************************************
Fingers Total
1 2
1 6
Correct total is 2
PLAYER 1 WINS
*****************************************************************************************************
Fingers Total
2 1
4 6
Correct total is 6
PLAYER 2 WINS
*/