-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path7.cpp
More file actions
51 lines (50 loc) · 1.6 KB
/
Copy path7.cpp
File metadata and controls
51 lines (50 loc) · 1.6 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
#include <iostream>
using namespace std;
int main(){
int player=1,left,first=1,rmove=1;
cout << "Matchstick Game" << endl;
cout << "How many matchsticks do you want?";
cin >> left;
cout << endl;
cout << "Game start." << endl << "Player1 go first."<<endl;
while(left>0){
if (player==1){
cout << "Player1:";
cin >> rmove;
if (rmove>=0&&rmove <=3){
if (left-rmove<0){
cout << "Warning: Please input a smaller number." << endl;
player=1;
}else{
left=left-rmove;
player=2;
cout << "There are " << left << " left." << endl;
}
}else{
cout << "Warning: Please input number 1,2 or 3." << endl;
player=1;
}
}else if(player=2){
cout << "Player2:";
cin >> rmove;
if (rmove>=0&&rmove <=3){
if (left-rmove<0){
cout << "Warning: Please input a smaller number." << endl;
player=2;
}else{
left=left-rmove;
player=1;
cout << "There are " << left << " left." << endl;
}
}else{
cout << "Warning: Please input number 1,2 or 3." << endl;
player=2;
}
}
}
if(player==2){
cout << "Player1 WIN"<<endl;
}else{
cout << "Player2 WIN"<<endl;
}
}