-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathmain.cpp
More file actions
72 lines (66 loc) · 1.87 KB
/
Copy pathmain.cpp
File metadata and controls
72 lines (66 loc) · 1.87 KB
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
#include <iostream>
#include <cstdlib> // for rand(), srand()
#include <ctime> // for time()
using namespace std;
int main()
{
string playerName = "";
int playerDecision = 0;
bool playerSteal = false;
bool computerSteal = false;
char playAgain = ' ';
int playGame = 0;
int playerPoints = 0;
int computerPoints = 0;
// Seed the random number generator
srand(time(0));
cout << "Welcome to Split or Steal!\nWhat's your name? ";
getline(cin, playerName);
do{
do{
cout << playerName << " make a choice:\n";
cout << "1 - Split\n";
cout << "2 - Steal\n";
cout << "Enter the number of your choice: ";
cin >> playerDecision;
if ( playerDecision == 1 ){
playerSteal = false;
cout << playerName << " chose to Split\n";
}
else if( playerDecision == 2 ){
cout << playerName << " chose to Steal\n";
playerSteal = true;
}
else {
cout << "Invalid choice.\n";
}
}while( playerDecision != 1 && playerDecision !=2 );
// Randomize computer choice
computerSteal = rand() % 2;
if( computerSteal ){
cout << "Computer chose to Steal.\n";
}
else {
cout << "Computer chose to Split.\n";
}
// booleans: playerSteal and computerSteal
if( playerSteal && computerSteal ) {
cout << "Greedy! You both lose!\n";
}
else if( playerSteal && !computerSteal ) {
cout << "Congrats, you win the whole prize!\n";
playerPoints += 2;
}
else if( !playerSteal && computerSteal ) {
cout << "Oh no, the computer stole the whole prize!\n";
computerPoints += 2;
}
else {
cout << "You and the computer each get 50% of the prize!\n";
playerPoints++;
computerPoints++;
}
playGame++;
}while( playGame < 3);
return 0;
}