- #include<iostream>
- #include<cstdlib>
- #include<time.h>
- using namespace std;
- int main()
- {
-
- int player =0;
- int computer = 0;
-
- cout << "請出拳 輸入:(1)剪刀(2)石頭(3)布"<< endl;
- cin >> player;
- string data [] = {"剪刀","石頭","布"};
- srand(time(NULL));
- computer = (rand()%3)+1;
-
- cout << "你出 :" << data[player-1]<<endl;
- cout << "電腦出 :" << data[computer-1]<<endl;
- cout << "結果: ";
-
- if(player ==computer)
- {
- cout << "Tie" << endl;
- }
-
- else if(player ==1 && computer == 3)
- {
- cout << "you win" << endl;
- }
-
- else if(player ==2 && computer == 1)
- {
- cout << "you win" << endl;
- }
-
- else if(player ==3 && computer == 2)
- {
- cout << "you win"<<endl;
- }
-
- else
- {
- cout << "you lose" << endl;
- }
-
-
- system("pause");
- return 0;
- }
複製代碼 |